Cursor :
Cursor is a memory area,that hold the data of query which is assigned to cursor.
Purpose of Cursor :
We can not use query in PLSQL block which returns more than 1 row, to handle that query we use cursor.
There are 2 types of cursor.
1) Implicit Cursor
2) Explicit Cursor
Implicit Cursor :
Implicit cursor is managed by the Oracle internally for query.
Explicit Cursor :
Explicit cursor managed by user.
There are following steps need to follow sequentially for use cursor.
1) Declaration
cursor is ;
2) Open
open ;
3) Fetch
fetch into ;
4) close
close ;
Syntax:
declare
cursor cur_emp is select emp_sal from emp;
l_emp_sal emp.emp_sal%type;
begin
open cur_emp;
loop
fetch cur_emp into l_emp_sal;
exit when cur_emp%notfound;
dbms_output.put_line( l_emp_sal);
end loop; ;
dbms_output.put_line('Processed records:-'||cur_emp%rowcount);
close cur_emp;
end;
No comments:
Post a Comment
Please do not enter any spam link in the comment box.