Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6208777
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T05:51:59+00:00 2026-05-24T05:51:59+00:00

SELECT id FROM table_name tkn1, (SELECT id, ROWNUM rnum FROM table_name WHERE PROCS_DT is

  • 0
SELECT 
        id
        FROM table_name tkn1,
        (SELECT 
            id, 
            ROWNUM rnum
         FROM table_name 
         WHERE 
            PROCS_DT is null
         order by PRTY desc, CRET_DT) result 
        WHERE  tkn1.id= result.id
        AND result.rnum <= 10 FOR UPDATE OF tkn1.id SKIP LOCKED

Here is my problem. 2 threads are accessing this query at the same time

Thread 1 – Executes select and locks 10 rows ordered by descending priority and created date. Next I would update the procs_dt as todays date from a separate query..

Thread 2 – Before update of procs_dt or commit happens from thread 1 , this thread executes this query. My requirement is that the next 10 unlocked rows must be handed over to thread 2. But what really happens is the same set of locked rows comes out of the inner query since procs_dt is still null and yet to be updated by thread 1 and since skip locked is given in the outer query, all those 10 rows are skipped and no records are returned for thread 2 to process

This ultimately defeats my multi threading requirement.

How to fix this query? I tried adding the skip locked to the inner query. But oracle 11g doesn allow it.

Experts please help. I am using oracle 11g

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T05:52:01+00:00Added an answer on May 24, 2026 at 5:52 am

    I’d go with something like this :
    A cursor to select the rows in order for update, and use the LIMIT clause to get the first ten available.

    create table gm_temp
    as select rownum id, table_name obj_name, date '2011-01-01' + rownum create_date 
    from all_tables where rownum < 500;
    
    CREATE TYPE tab_number IS TABLE OF NUMBER;
    
    DECLARE
      cursor c_table IS 
        SELECT id FROM gm_temp ORDER BY create_date DESC FOR UPDATE OF id SKIP LOCKED;
      t_table_src tab_number := tab_number();
    BEGIN
      OPEN c_table;
      FETCH c_table BULK COLLECT INTO t_table_src LIMIT 10;
      CLOSE c_table;
      dbms_output.put_line(':'||t_table_src.count||':'||t_table_src(1));
    END;
    

    Actually, I’d firstly see whether processing ALL outstanding rows as a set would be better than multi-threading.

    Then if I did decide that I needed some form of multi-threading, I’d look at pipelined functions with parallel enabled (assuming I was on Enterprise Edition).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I written a query in my sql like this: select * from table_name order
Suppose we have this query: ResultSet result = (select * from table_name); Now we
PHP mySQL query: $query = SELECT * FROM table_name ORDER BY id < 3,
When using this SQL query: Select * from table_name what happens if the name
When we execute select count(*) from table_name it returns the number of rows. What
For example, mysql quote table name using SELECT * FROM `table_name`; notice the `
I am using this: SELECT FROM_UNIXTIME(my_unix_timestamp_column, '%Y') AS year FROM table_name WHERE year =
Let's say I have a query like this: SELECT * FROM table_name WHERE venue
this is my php code $sql=SELECT * FROM table_name WHERE FROM_UNIXTIME(date, '%Y') = $q
Two similar queries: firstQuery = select * from table_name where column_name = match_value secondQuery

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.