6

在 Oracle 中,我可以选择排序表中的前 1 条消息

select messageid from(
    select 
        messageid, 
        RANK() over (order by messageid asc) as msg_rank 
    from messages
) where msg_rank=1;

正如我在上一个问题中发现的那样,我可以专门选择一行

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 个?

4

1 回答 1

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;
于 2010-10-15T04:01:17.557 回答