您的位置:首页 > 其它

where current of 子句

2014-05-15 10:54 260 查看
PL/SQL提供为update和delete语句在cursor中使用提供了where current of子句。这个子句让你容易地进行update和delete操作对最近fetch的行进行操作。 

语法: 

UPDATE table_name 

       SET set_clause 

     WHERE CURRENT OF cursor_name; 

  DELETE 

      FROM table_name 

     WHERE CURRENT OF cursor_name 

使用这个子句的作用主要是对上一次fetch的行进行update和delete操作,不需要在where条件中写=表达式,让where条件更简单,自动定位行。例子如下: 

-- where current of cursor 

declare 

  cursor cemp is 

    select * from employees for update;--要结合for update使用 vemp cemp%rowtype; 

begin 

  open cemp; 

  loop 

   fetch cemp into vemp; 

   exit when cemp%notfound; 

    update employees set salary=salary*1.2 where current of cemp;--where current of 

  end loop; 

  commit; 

  close cemp; 

end;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: