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

  • Home
  • SEARCH
  • 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 483245
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T01:10:40+00:00 2026-05-13T01:10:40+00:00

I have an table (in ORADB) containing two columns: VARCHAR unique key and NUMBER

  • 0

I have an table (in ORADB) containing two columns: VARCHAR unique key and NUMBER unique key generated from an sequence.

I need my Java code to constantly (and in parallel) add records to this column whenever a new VARCHAR key it gets, returning the newly generated NUMBER key. Or returns the existing NUMBER key when it gets an existing VARCHAR (it doesn’t insert it then, that would throw an exception of course due to the uniq key violation).

Such procedure would be executed from many (Java) clients working in parallel.

Hope my English is understandable 🙂

What is the best (maybe using PL/SQL block instead of Java code…) way to do it?

  • 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-13T01:10:40+00:00Added an answer on May 13, 2026 at 1:10 am

    I do not think you can do better than

    1. SELECT the_number FROM the_table where the_key = :key

    2. if found, return it

    3. if not found, INSERT INTO the_table SELECT :key, the_seq.NEXT_VAL RETURNING the_number INTO :number and COMMIT

    4. this could raise a ORA-00001(duplicate primary key insert)
      if the timing is unlucky. In this case, SELECT again.

    Not sure if JDBC supports RETURNING, so you might need to wrap it into a stored procedure (also saves database roundtrips).

    You can use an index-organized table (with the_key as primary key), makes the lookup faster.

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

Sidebar

Related Questions

i have table consist of columns : id,name,job and i have row stored with
I have table dates as following dates one two three four date1 id1 id2
I have table columns with values in them and when you click the edit
I have table with 2 columns .... id id2 1 1 1 2 1
I have table with 20 to 30 rows and 3 columns. I would like
I have table with ID who is PK and I have in same table
i have table , contain firstname and lastname , i used in my query
I have table sort of like Name |DateOfEvent|EventType ---------------------------------- Smith |10/1/2005 |New Thomas |1/1/2002
I have table Event and table Sessions and each event has a set of
I have table with ID, startIPNum and endIPNum. startIPNum and endIPNum are already converted

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.