How to update cursor records using WHERE CURRENT OF?

大憨熊 提交于 2019-12-08 06:01:40

问题


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

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:

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; 

回答1:


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



来源:https://stackoverflow.com/questions/13207379/how-to-update-cursor-records-using-where-current-of

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!