在Oracle中,我可以使用
选择排序表中的前1条消息select messageid from(
select
messageid,
RANK() over (order by messageid asc) as msg_rank
from messages
) where msg_rank=1;
正如我在previous question中发现的那样,我可以用
选择一行select * from messages where rownum < 2 for update skip locked;
但是我无法将这两个概念合并在一起
select messageid from(
select
messageid,
RANK() over (order by messageid asc) as msg_rank
from messages
) where msg_rank=1 for update skip locked;
-- results in error
-- ORA-02014: cannot select FOR UPDATE from view with DISTINCT, GROUP BY, etc.
如何通过readpast锁定选择前N个?
答案 0 :(得分:3)
这会有用吗?
select messageid from messages
where messageid in (
select messageid from(
select
messageid,
RANK() over (order by messageid asc) as msg_rank
from messages
) where msg_rank=1
)
for update skip locked;