oracle 如何解决 ORA-02014:无法使用 DISTINCT、GROUP BY 等从视图中选择 FOR UPDATE
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3166615/
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
How to work around ORA-02014: cannot select FOR UPDATE from view with DISTINCT, GROUP BY, etc
提问by jva
I want to lock one record in a table. The record is specified as "the next that has ID greater than..."
我想锁定表中的一条记录。该记录被指定为“下一个 ID 大于...”
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.
我确实需要现有查询保持不变,因为它是一个游标,并且有几个地方使用了这个游标的 %rowtype。
回答by DCookie
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;