How to work around ORA-02014: cannot select FOR UPDATE from view with DISTINCT, GROUP BY, etc

北战南征 提交于 2019-12-01 06:40:46

问题


I want to lock one record in a table. The record is specified as "the next that has ID greater than..."

CREATE TABLE test (id number);

SELECT id
FROM (SELECT id 
      FROM test
      WHERE id > 10
      ORDER BY id)
WHERE ROWNUM = 1
FOR UPDATE;

This seems intuitive and easy. But it is not. Any ideas?

P.S.

I do need the existing query to remain the same because it is a cursor and there are several places that use this cursor's %rowtype.


回答1:


I think you're going to need something like:

SELECT id
  FROM test
 WHERE id =
       (SELECT MIN(id) 
          FROM test
         WHERE id > 10)
FOR UPDATE;


来源:https://stackoverflow.com/questions/3166615/how-to-work-around-ora-02014-cannot-select-for-update-from-view-with-distinct

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