title: FOR UPDATE SKIP LOCKED with ROWNUM on ORACLE 12c
body: <p>I searched all the forum but I didn't find any clue about it. 
  I have a staging table that multiple threads consume. 
  To avoid deadlock, I'm using something like this: </p>
  
  <pre><code>SELECT ID_MESSAGE
  FROM TB_STAGE_IN S 
  WHERE S.CD_STATUS = 0 
  AND S.ID_JOB_SCHEDULE IS NULL 
  AND ROWNUM &lt;= 10000 
  FOR UPDATE SKIP LOCKED; 
  </code></pre>
  
  <p>It works fine, but the threads don't reach the max of 10,000 rows. 
  It's like: </p>
  
  <ul>
  <li>Thread 1: 5000</li>
  <li>Thread 2: 3000</li>
  <li>Thread 2: 2000</li>
  </ul>
  
  <p>I know that happens because the rownumber for them is the same, but the table has thousands and thousands of rows. What I really need is the thread gets 10,000 rows unlocked on every step. </p>
  
  <p>I tried using FETCH FIRST 10000 ROWS ONLY, but I receive the message below: 
  ORA-02014: cannot select FOR UPDATE from view with DISTINCT, GROUP BY, etc. </p>
  
  <p>Could you all please help me?</p>
  
  <p>Thanks for the kind. </p>