Oracle 使用游标删除单行

create or replace procedure pro_cursor_delete
(
    inpit_taid number
)
as
  v_taid number;

cursor c_delete is select taid from table3 where taid=inpit_taid
for update of taid; --锁定taid列的单行值,防止所有的数据被删除了
begin
open c_delete;
loop
fetch c_delete into v_taid;
exit when c_delete%notfound;
  delete table3 where taid=inpit_taid;
end loop;
  commit;
  dbms_output.put_line('taid=:' ||inpit_taid);
close c_delete;
end pro_cursor_delete;

相关推荐