1

我在java中有以下准备好的语句:

with main_select as 
  (select request_id,rownum iden
   from 
    (select request_id
     from queue_requests
     where request_status = 0 and
           date_requested <= sysdate and
           mod(request_id,?) = ?
     order by request_priority desc, oper_id, date_requested)   
   where rownum < ?) 

select *
from queue_requests qr, main_select ms
where qr.request_id in ms.request_id
order by ms.iden for update skip locked;

它不执行:

ORA-02014: 无法从具有 DISTINCT、GROUP BY 等的视图中选择 FOR UPDATE。

我将尝试解释为什么我需要所有选择语句:

  • 第一个(内部)选择获得我需要的数据
  • 第二个将行数限制为一个数字(我不能把它放在第一个选择中,因为oracle首先限制结果并且只有在对它们进行排序之后,这不是我想要的)
  • 第三个(外部)选择保留顺序(我尝试使用 3 个嵌套选择 - 所以,没有 with 子句 - 但在这种情况下我找不到保留顺序的方法)。此外,它应该锁定 queue_requests 表中的行,但是因为我从 with 子句中选择了数据,所以它给出了上述错误。

所以,我想从 queue_requests 中选择数据,保留前 x 行,保留选择的顺序并锁定行。

有没有办法做到这一点?

4

1 回答 1

0

The problem seems to be, that you want to set a lock on the result of main_select. I would just guess, that you can do select for update in the select in the with clause like:

with main_select as 
  (select request_id,rownum iden
   from (subselect)
   where rownum < ?
   for update skip locked)

But as I said lucky guess.

于 2013-07-10T09:00:52.367 回答