PL / SQL:删除游标内的行不起作用

时间:2015-11-16 14:54:55

标签: oracle plsql sql-delete

如何从PL / SQL游标循环中的表中删除行?猜猜,我对这段代码做错了什么:

DECLARE
  CURSOR myCursor IS SELECT * FROM A WHERE <some-condition> FOR UPDATE;
BEGIN
  FOR x IN myCursor LOOP
    DELETE FROM A WHERE CURRENT OF myCursor;
  END LOOP;
END;

如果我用DELETE替换UPDATE语句,一切都按预期工作(除此之外,记录只会更新而不是删除)。例如:

DECLARE
  CURSOR myCursor IS SELECT * FROM A WHERE <some-condition> FOR UPDATE;
BEGIN
  FOR x IN myCursor LOOP
    UPDATE A SET FOO = 'bar' WHERE CURRENT OF myCursor;
  END LOOP;
END;

0 个答案:

没有答案