oracle 如何使用 WHERE CURRENT OF 更新游标记录?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13207379/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 04:36:19  来源:igfitidea点击:

How to update cursor records using WHERE CURRENT OF?

oracleplsqlcursor

提问by Centurion

I'm getting "ORA-01410: Invalid ROWID" exception when executing this block. Any ideas why?

执行此块时出现“ORA-01410:无效的ROWID”异常。任何想法为什么?

DECLARE
  CURSOR c_orders IS
    SELECT * from orders FOR UPDATE OF no;
  v_order_record c_orders%ROWTYPE;
BEGIN
  OPEN c_orders; 
  LOOP
    FETCH c_orders INTO v_order_record;
    UPDATE orders SET no = 11 WHERE CURRENT OF c_orders;
    EXIT WHEN c_orders%NOTFOUND; 
  END LOOP;  
  CLOSE c_orders; 
END; 

However, everything works if using FOR IN syntax:

但是,如果使用 FOR IN 语法,一切正常:

DECLARE
  CURSOR c_orders IS
    SELECT * from orders FOR UPDATE OF no;
BEGIN
  FOR rec IN c_orders
  LOOP
    UPDATE orders SET no = 11 WHERE CURRENT OF c_orders;
  END LOOP; 
END; 

回答by Mat

Move the exit whento before the update- you can't update something that doesn't exist.

exit whento 移到update- 您无法更新不存在的内容。