Fetch single column cursor to varchar2 variable : Cursor Fetch « Cursor « Oracle PL / SQL






Fetch single column cursor to varchar2 variable

 

SQL> CREATE TABLE products(
  2    product_id              NUMBER(6),
  3    name            VARCHAR2(50)
  4  );

Table created.

SQL>
SQL>
SQL>
SQL> declare
  2      v_name varchar2(80);
  3      cursor get_data is select name from products;
  4    begin
  5       open get_data;
  6       fetch get_data into v_name;
  7       dbms_output.put_line(v_name);
  8       close get_data;
  9  end;
 10  /

PL/SQL procedure successfully completed.

SQL>
SQL>
SQL> drop table products;

Table dropped.

   
  








Related examples in the same category

1.Below is a function that demonstrates how to use the FETCH statement
2.Fetch value from cursor
3.Fetches the records from a cursor variable that returns employee information
4.Fetch cursor to two variables
5.legal and illegal FETCH statements.
6."ORA-1002: fetch out of sequence" because of the commit inside the SELECT..FOR UPDATE loop.
7.A WHILE cursor fetch loop.
8.Different BULK_COLLECT statements used for bulk binds
9.Check Cursor%FOUND after fetching
10.Fetch value in cursor until NOTFOUND
11.ORA-01002: fetch out of sequence
12.Fetch out cursor value and insert to another table
13.PLS-00394: wrong number of values in the INTO list of a FETCH statement
14.FETCH cursor BULK COLLECT
15.Fetch cursor data to number variable
16.Fetch cursor till cursorVariable%notfound
17.Fetch cursor to table collection of row type
18.Fetch cursor value to three variables
19.Fetch row by row