儲存過程 cursor

2021-06-16 10:18:27 字數 1656 閱讀 3025

-----儲存過程游標使用篇-----

-- 1.隱式游標 : 隱式cursor是系統自動開啟和關閉cursor.

--sql%rowcount 整型 代表dml語句成功執行的資料行數

--sql%found  布林型  值為true代表插入、刪除、更新或單行查詢操作成功

--sql%notfound 布林型 與sql%found屬性返回值相反

--sql%isopen 布林型 dml執行過程中為真,結束後為假

begin

update student set s_name = 'modify' where s_id = 4; 

if(sql%found) then

dbms_output.put_line('find the rowdata 。。。');

commit;

else

dbms_output.put_line('unfind the rowdata 。。。');

rollback;

end if;

end;

-- 2.顯示游標

declare

cursor cur is select * from student;

cursor cur2 is select * from student;

sturow student%rowtype;

begin

for stu in cur loop

--sturow := stu;

dbms_output.put_line(stu.s_name);

end loop;

open cur2;

loop

fetch cur2 into sturow;

exit when cur2%notfound;

dbms_output.put_line(sturow.s_name);

end loop;

dbms_output.put_line(cur2%rowcount);

if(cur2%isopen) then

dbms_output.put_line('-close cur2-');

close cur2;

end if;

end;

-- 3.動態游標

declare

type cursor_type is ref cursor;

cur cursor_type;

sqlstr varchar2(40);

rowdata student%rowtype;

begin

sqlstr := 'select * from student';

open cur for sqlstr;

loop

fetch cur into rowdata;

if(cur%notfound) then

exit;

dbms_output.put_line('-not find ...-');

end if;

dbms_output.put_line('-data-'||rowdata.s_name);

end loop;

if(cur%isopen) then

close cur;

end if;

end;

儲存過程CURSOR使用

create or replace procedure pro exec stat ascursor log info is select route value,process time,rsp code,rsp desc from log inte ce detail cursor area i...

oracle儲存過程cursor

遍歷gws payment notice表,根據wfr no查詢gws write off record 根據gws write off record的source id查詢gws payment notice detail,如果不存在,則對gws payment notice detail作新增操...

oracle儲存過程 cursor使用

create or replace procedure test is v count number 4 cursor v c is select from t2voucherhandno begin select count into v count from t2voucherhandno if...