There are five cursor attributes:
%isopen
%found
%notfound
%rowcount
%bulk_rowcount
------------------------------------------------------------------------------
%isopen
With %isopen it is possible to test whether a cursor was opened:
declare
cursor cur_emp is
SELECT NAME
FROM EMP;
l_name
begin
open cur_emp;
fetch cur_emp into l_name;
if cur_emp%isopen
then
log("Cursor is Open")
end if;
close cur;
end;
If there are records in EMP table then the message "Cursor is Open" will be logged at the terminal.
------------------------------------------------------------------------------
%found returns true when the last fetch operation on the cursor fetched a row.
%notfound returns true when the last fetch operation on the cursor did not fetch a row.
declare
cursor cur_emp is
SELECT NAME
FROM EMP;
begin
open cur_emp;
Loop
if cur_emp%found
then
log("Record returned");
elsif cur_emp%notfound
log("No records");
exit;
end if;
close cur;
end;
If there are 5 records in EMP TABLE then you will get "Record returned" message five times and then
loop will exit logging the message "No records".
%NOTFOUND is mostly used to exit the LOOP for cursor after the last record has been fetched/processed.
---------------------------------------------------
%rowcount returns the number of rows that have been fetched so far
example;
declare
cursor cur_emp is
SELECT NAME
FROM EMP;
begin
open cur_emp;
loop
if cur%found then
dbms_output.put_line(cur%rowcount);
else
exit;
end if;
end loop;
end;
%bulk_rowcount is similar to %rowcount, but is used in bulk collects.
%isopen
%found
%notfound
%rowcount
%bulk_rowcount
------------------------------------------------------------------------------
%isopen
With %isopen it is possible to test whether a cursor was opened:
declare
cursor cur_emp is
SELECT NAME
FROM EMP;
l_name
begin
open cur_emp;
fetch cur_emp into l_name;
if cur_emp%isopen
then
log("Cursor is Open")
end if;
close cur;
end;
If there are records in EMP table then the message "Cursor is Open" will be logged at the terminal.
------------------------------------------------------------------------------
%found returns true when the last fetch operation on the cursor fetched a row.
%notfound returns true when the last fetch operation on the cursor did not fetch a row.
declare
cursor cur_emp is
SELECT NAME
FROM EMP;
begin
open cur_emp;
Loop
if cur_emp%found
then
log("Record returned");
elsif cur_emp%notfound
log("No records");
exit;
end if;
close cur;
end;
If there are 5 records in EMP TABLE then you will get "Record returned" message five times and then
loop will exit logging the message "No records".
%NOTFOUND is mostly used to exit the LOOP for cursor after the last record has been fetched/processed.
---------------------------------------------------
%rowcount returns the number of rows that have been fetched so far
example;
declare
cursor cur_emp is
SELECT NAME
FROM EMP;
begin
open cur_emp;
loop
if cur%found then
dbms_output.put_line(cur%rowcount);
else
exit;
end if;
end loop;
end;
%bulk_rowcount is similar to %rowcount, but is used in bulk collects.
3 comments:
Oracle Apps R12 and Fusion Cloud Self Paced Training Videos by Industry Experts. Please Check https://www.oracleappstechnical.com
Oracle Apps R12 and Oracle Fusion Cloud Self Paced Online Training Videos Published on Udemy with Life Time Access & Live Meeting Support to Clear your Queries. Avail 25% to 80% discount. Please Check https://www.oracleappstechnical.com for Never Before Offers and Discount Coupon Codes.
25% OFF on Oracle Apps R12 Financials Self Paced Course along with 11 Additional Add On Courses (321 Session Videos of 120 Hours Recordings). Our Top Trending Course with 1700 Enrolled Udemy Students
Please Check https://www.oracleappstechnical.com for details
Post a Comment