title: oracle stored procedure - select, update and return a random set of rows
body: <p>oracle i wish to select few rows at random from a table, update a column in those rows and return them using  stored procedure</p>
  
  <pre><code>PROCEDURE getrows(box IN VARCHAR2,   row_no IN NUMBER,   work_dtls_out OUT dtls_cursor) AS
  
    v_id VARCHAR2(20);
    v_workname VARCHAR2(20);
    v_status VARCHAR2(20);
  
    v_work_dtls_cursor dtls_cursor;
  
  BEGIN
  
    OPEN v_work_dtls_cursor FOR
      SELECT id, workname, status
      FROM item 
      WHERE status IS NULL
      AND rownum &lt;= row_no 
    FOR UPDATE;
  
    LOOP
      FETCH v_work_dtls_cursor
      INTO  v_id ,v_workname,v_status;
  
      UPDATE item
      SET status = 'started'
      WHERE id=v_id;
  
      EXIT
       WHEN v_work_dtls_cursor % NOTFOUND;
    END LOOP;
  
    close v_work_dtls_cursor ;
  
    /* I HAVE TO RETURN THE SAME ROWS WHICH I UPDATED NOW. 
       SINCE CURSOR IS LOOPED THRU, I CANT DO IT.  */
  
  END getrows;
  </code></pre>
  
  <p>PLEASE HELP</p>