您的位置:首页 > 数据库 > Oracle

Oracle 更新或者删除游标行

2017-03-21 14:00 260 查看
-- 更新或删除游标行
/*注:当使用游标更新或者删除游标时,定义游标必须带有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;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: