Connecting Tech Pros Worldwide Forums | Help | Site Map

PL/SQL-CURSOR - 1

debasisdas's Avatar
Moderator
 
Join Date: Dec 2006
Location: Bangalore ,India
Posts: 7,508
#1   May 28 '07
This thread contains some useful tips/samples regarding cursors, that the forum members may find useful.

Cursor
===========
Implicit Cursor--sql Returns Single Line. Created By Oracle Server.
Explicit Cursor--sql Retuns Multiple Line Of Record. Created By User.
----------
Cursor Life Cycle
----------
Declare-->open-->fetch-->check Last Record-->close

Basic Syntax
---------------------------
Expand|Select|Wrap|Line Numbers
  1. Declare
  2. Cursor Cursorname [(param1,param2,....)]
  3. Is Select Statment [for Update [of Col1,col2,..];
  4. Begin
  5. Open Cursorname[(input Arguments)];
  6. Loop
  7. Fetch Cursorname Into V1,v2,.....;
  8. End Loop;
  9. Close Cursorname;
  10. End;
  11.  
----CURSOR ATTRIBUTES---

%FOUND---returns--BOOLEAN
%NOTFOUND--returns---BOOLEAN
%ISOPEN--returns---BOOLEAN
%ROWCOUNT---returns---INTEGER
%BULKROWCOUNT----returns-----INTEGER

Sample test code for cursor.
=======================
Expand|Select|Wrap|Line Numbers
  1. DECLARE
  2. I EMP.EMPNO%TYPE;
  3. J EMP.ENAME%TYPE;
  4. CURSOR C IS SELECT EMPNO,ENAME FROM EMP;
  5. BEGIN
  6. OPEN C;
  7. LOOP
  8. FETCH C INTO I,J;
  9. DBMS_OUTPUT.PUT_LINE(I||'       '||J);
  10. EXIT WHEN C%NOTFOUND;
  11. END LOOP;
  12. CLOSE C;
  13. END;
  14.  

Please try on SCOTT Schema


Also check PL/SQL-CURSOR - 2



Reply