GeekInterview.com
   Home |  Tech FAQ  |   Interview Questions |  Placement Papers |  Tech Articles |  Learn |  Freelance Projects |  Online Testing |  Geeks Talk |  Job Postings |  Knowledge Base | Site Search |  Add/Ask Question

  GeekInterview.com  >  Interview Questions  >  Oracle  >  SQL

 Print  |  
Question:  Difference between an implicit & an explicit cursor.


Answer:
PL/SQL declares a cursor implicitly for all SQL data manipulation statements, including quries that return only one row. However,queries that return more than one row you must declare an explicit cursor or use a cursor FOR loop.
Explicit cursor is a cursor in which the cursor name is explicitly assigned to a SELECT statement via the CURSOR...IS statement. An implicit cursor is used for all SQL statements Declare, Open, Fetch, Close. An explicit cursors are used to process multirow SELECT statements An implicit cursor is used to process INSERT, UPDATE, DELETE and single row SELECT. .INTO statements.


October 10, 2006 14:13:59 #8
 rampratap409   Member Since: September 2006    Total Comments: 108 

RE: Difference between an implicit & an explicit c...
 

Implicit cursor will select and return only (only) one row

like :

select ename, job into v_ename, v_job

from emp

where empno = 7839;

Explicit cursor can have one row or multiple

like in previous example its explicit because statement may return more then one row.

another example for explict cursor:

declare

cursor c1 is select ename, job, sal from emp;

v_ename emp.ename%type;

v_job emp.job%type;

v_sal emp.sal%type;

begin

open c1;

loop

fetch c1 into v_ename, v_job, v_sal;

exit when c1%notfound;

dbms_output.put_line(v_ename||'  '|v_job||'  '||v_sal);

end loop;

end;

/

     

 

Back To Question