Tuesday, February 7, 2017

Cusor Attributes

declare
Cursor C1 is Select * from Apps;
cursor_test C1%rowtype;
begin
open C1;
loop
fetch C1 into Cursor_test;
exit when C1%notfound;--notfound
end loop;
Close C1;
end;
/

declare
Cursor C1 is Select * from Apps;
cursor_test C1%rowtype;
begin
open C1;
loop
fetch C1 into Cursor_test;
exit when C1%notfound;--notfound
end loop;
dbms_output.put_line(C1%rowcount);--No of rows feched into the variable
Close C1;
end;
/


declare
Cursor C1 is Select * from Apps;
cursor_test C1%rowtype;
begin
open C1;
loop
fetch C1 into Cursor_test;
exit when C1%notfound;--notfound
end loop;
dbms_output.put_line(C1%rowcount);--No of rows feched into the variable
Close C1;
Exception
when others then
if C1%isopen then-- is open Cursor Attribute
Close C1;
end if;
end;
/


DECLARE
CURSOR C1 IS
SELECT * FROM APPS;
Cursor_test C1%rowtype;
BEGIN
IF NOT C1%ISOPEN THEN
OPEN C1;
END IF;
FETCH C1 INTO Cursor_test;
if C1%FOUND THEN
LOOP
fetch C1 into Cursor_test;
end loop;
end if;
Close C1;
end;
/

No comments:

Post a Comment