Oracle 更新或者删除游标行

来源:互联网 发布:淘宝三国杀ol卡是什么 编辑:程序博客网 时间:2024/05/16 08:10
-- 更新或删除游标行
/*注:当使用游标更新或者删除游标时,定义游标必须带有for update子句,在执行更新或者删除游标时必须带有 where current of 子句*/

-- 例:更新游标行
declare
  cursor e_cursor is
    select * from tg_test_user for update;
    dno int :=&no;
begin
 for e_record in e_cursor loop
   if e_record.tg_test_userid = dno  then
     dbms_output.put_line('用户名:'||e_record.tg_test_username||',密码:'||e_record.tg_test_password||',ID:'||e_record.tg_test_userid);
     update tg_test_user set tg_test_username='chao'where current of e_cursor;
     end if;
   end loop;
end;

--删除游标行
declare
 cursor e_cursor is  select * from tg_test_user for update;
 names varchar2(225):=lower('&name');
 begin
   for e_record in e_cursor loop
   if lower(e_record.tg_test_username)= names then
     null;
       delete from tg_test_user where current of e_cursor;
   else
      dbms_output.put_line('用户名:'||e_record.tg_test_username||',密码:'||e_record.tg_test_password||',ID:'||e_record.tg_test_userid);
   end if;
   end loop;
 end;

0 0
原创粉丝点击