PL SQL Tutorial
In PL/SQL Cursors are Name Assigned to Memory Area.
Implicit Cursors, Opening a cursor,Fetching records, and Closing a cursor, these operations done by PL/SQL Engine. User has no knowledge how it is done, internally PL/SQL performs These operations on behalf of User. Anyway Programmer can check cursor status using following Cursor Attributes.
Implicit Cursor Attributes
declare begin for idx in (select * from emp) loop dbms_output.put_line(idx.empno|| ' ' || idx.ename); end loop; end;Example2:
declare cursor c is select * from emp; emp_rec emp%ROWTYPE; begin /*for idx in c loop dbms_output.put_line(idx.empno|| ' ' || idx.ename); end loop; */
Steps required to use Explicite Cursor
Explicit Cursor Attributes
returns TRUE when cursor is opened.
returns TRUE when record fetched successfully
returns TRUE when record was not fetched successfully
returns number of records fetched from the cursor.
declare cursor c is select * from emp; emp_rec emp%ROWTYPE; begin open c; loop fetch c into emp_rec; exit when c%NOTFOUND; dbms_output.put_line(emp_rec.empno||' '||emp_rec.ename); end loop; close c; end;
ADS