首页 > 解决方案 > oracle:如何在分页中选择更新?

问题描述

在分页的情况下锁定查询的有限结果:

select * from Employee order by id asc

作为

select * from (select a.*, ROWNUM rnum from 
(select * from Employee order by id asc) a 
where ROWNUM <= 10) where rnum  >= 6 for update

错误:

ORA-02014: cannot select FOR UPDATE from view with DISTINCT, GROUP BY, etc.

如何在分页中选择更新行?

标签: oracleoracle11gpaginationlocking

解决方案


在这种情况下,您必须将 ROWID 与 FOR UPDATE 子句一起使用。

尝试:

select * from
Employee
where rowid in
(
  select r from
    (select rowid r from
     Employee
     order by id asc
    ) a
    where rownum <= 10
) for update;

推荐阅读