An example of cursor variable assignment : Introduction « Cursor « Oracle PL/SQL Tutorial






SQL>
SQL> create table product(
  2     product_id number(4)     not null,
  3     product_description varchar2(20) not null
  4  );

Table created.

SQL>
SQL> insert into product values (1,'Java');

1 row created.

SQL> insert into product values (2,'Oracle');

1 row created.

SQL> insert into product values (3,'C#');

1 row created.

SQL> insert into product values (4,'Javascript');

1 row created.

SQL> insert into product values (5,'Python');

1 row created.

SQL>
SQL>
SQL> DECLARE
  2    TYPE rc is REF CURSOR;
  3    refCursorValue1 rc;
  4    refCursorValue2 rc;
  5    myRecord product%ROWTYPE;
  6  BEGIN
  7    OPEN refCursorValue1 FOR SELECT * from product;
  8
  9    refCursorValue2 :=refCursorValue1;
 10    LOOP
 11      FETCH refCursorValue2 INTO myRecord;
 12      EXIT WHEN refCursorValue2%NOTFOUND;
 13      dbms_output.put_line(to_char(myRecord.product_id)||' '||
 14      rpad(myRecord.product_description,20,' '));
 15    END LOOP;
 16    CLOSE refCursorValue2;
 17  END;
 18  /
1 Java
2 Oracle
3 C#
4 Javascript
5 Python

PL/SQL procedure successfully completed.

SQL>
SQL> drop table product;

Table dropped.








25.1.Introduction
25.1.1.Cursors
25.1.2.First Cursor Example
25.1.3.An example of opening the cursorValue cursor
25.1.4.OPEN Cursor for fetching
25.1.5.A Cursor for counting
25.1.6.To prepare the comma-separated list
25.1.7.Create a cursor for update
25.1.8.An example of cursor variable assignment
25.1.9.Assigning different queries to the same cursor variable
25.1.10.Cursor to reference whole table
25.1.11.select first row to a cursor
25.1.12.Nested cursor
25.1.13.Cursor performance