11

我想使用以下查询锁定一组记录:

select *
  from (select *
          from event_table
         where status = 'S'
        order by creation_data asc
       )
 where rownum <=10
for update;

event_table 不是视图。这是一张普通的桌子:

create table event_table
(
 id            number, 
 creation_date date, 
 status        number, 
 info          clob
);

主键是字段 id。

我可以使用rownumwithselect for update吗?

是否有另一种解决方案,其中使用select for update但也只选择一组行而不是选择的所有结果?

例如,我有一个任务运行每个 X 内部并需要select for update用于该表,但如果选择返回 500 行,我只想每次处理 100 行(分页类型)。这就是我尝试这样做的原因rownum

谢谢。

4

1 回答 1

19

这行得通吗?:

select * from event_table where id in 
(
    SELECT id
    FROM (SELECT *
        FROM event_table
        WHERE status = 'S'
        ORDER BY CREATION_DATA ASC)
        WHERE ROWNUM <=10
)
FOR UPDATE;
于 2011-05-03T19:01:22.137 回答