Oracle游标属性介绍
cursor cursor1 is select 语句;open cursor1fetch cursor1 into v1,v2,...;close cursor1;%isopen测试游标是否打开,如果没有打开游标就使用fetch语句将提示错误。%found测试前一个fetch语句是否有值,有值返回true,否则返回false。%notfound是%found属性的
open cursor1
fetch cursor1 into v1,v2,...;
close cursor1;
%isopen测试游标是否打开,如果没有打开游标就使用fetch语句将提示错误。
%found测试前一个fetch语句是否有值,有值返回true,否则返回false。
%notfound是%found属性的反逻辑,常被用于退出循环。
%rowcount用于返回游标的数据行数。
create or replace procedure testProcedure is
cur1 types.cursorType;
tmpId varchar2(20);
sqlStr VARCHAR2(4000);
ret numeric(6);
begin
dbms_output.put_line('=======begin!');
open cur1 for select id from table1;
loop
fetch cur1 into tmpId ;
exit when cur1%notfound ;
--dbms_output.put_line('id = ' || tmpId);
sqlStr := ' select count(*) from user_tables where table_name like ''user_' || tmpId ';
--dbms_output.put_line('sqlStr = ' || sqlStr);
Execute immediate sqlStr into ret;
if ret = 0 then
dbms_output.put_line(tmpStrId);
end if;
end loop;
dbms_output.put_line('=======end!');
end testProcedure;
更多推荐



所有评论(0)