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 9179671
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T17:51:26+00:00 2026-06-17T17:51:26+00:00

In an oracle database-table I need to find a result for a given lot-number.

  • 0

In an oracle database-table I need to find a result for a given lot-number.
The field where lot-numbers are saved is a string containing something like ‘1-3,5,10-15,20’ (the numbers inside this string are sorted)

is there a way of doing this?

in the example above, the result should be found for the following lot-numbers:

1,2,3,5,10,11,12,13,14,15,20

There is no way to do it in the application, so it has to be done inside the databse.

something like: “SELECT * FROM products WHERE lot = 2”

  • 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-06-17T17:51:27+00:00Added an answer on June 17, 2026 at 5:51 pm

    It is possible to do this all in SQL by use of the REGEXP_SUBSTR function and hierarchical queries:

    with list_of_ids as (
    select regexp_substr(a, '[[:digit:]]+',1, 1) as lot1
         , nvl( regexp_substr(a, '(-)([[:digit:]]+)',1, 1, 'i', '2')
              , regexp_substr(a, '[[:digit:]]+',1, 1)) as lot2
      from (select regexp_substr('1-3,5,10-15,20' , '[^,]+', 1, level) as a
              from dual
           connect by regexp_substr('1-3,5,10-15,20' , '[^,]+', 1, level) is not null
                   )
           )
    select a.*
      from products a
      join list_of_ids b
        on a.lot between b.lot1 and b.lot2
    

    However, I must emphasise that normalising your database properly is the way to go. This solution may not scale well and does a hugely unnecessary amount of work.

    It works like this:

    First split your data on the comma:

    SQL>  select regexp_substr('1-3,5,10-15,20', '[^,]+', 1, level) as a
      2     from dual
      3  connect by regexp_substr('1-3,5,10-15,20', '[^,]+', 1, level) is not null
      4          ;
    
    A
    --------------
    1-3
    5
    10-15
    20
    

    Next, split it on the hyphen to provide a minimum and maximum lot to use in the BETWEEN before finally joining it to the table. The NVL is there to ensure that there is always a maximum.

    SQL> select regexp_substr(a, '[[:digit:]]+',1, 1) as lot1
      2       , nvl( regexp_substr(a, '(-)([[:digit:]]+)',1, 1, 'i', '2')
      3             , regexp_substr(a, '[[:digit:]]+',1, 1)) as lot2
      4    from (select regexp_substr('1-3,5,10-15,20' , '[^,]+', 1, level) as a
      5            from dual
      6         connect by regexp_substr('1-3,5,10-15,20' , '[^,]+', 1, level) is not null
      7                 )
      8         ;
    
    LOT1           LOT2
    -------------- --------------
    1              3
    5              5
    10             15
    20             20
    
    SQL>
    

    Here’s a working SQL Fiddle with the full query.

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

Sidebar

Related Questions

I have a table in a Oracle database containing a date field EXPIRYDATE. I
I need to insert more than 50k records to oracle database table, The process
So i need to update some dates on an Oracle Database, the field is
I need to diagram an oracle database and I am hoping to find some
I need to insert more than thousand rows into an Oracle Database table every
I am using oracle database While inserting a row in a table, i need
I have a table (in Oracle 9 and up) where I need to find
I need to find all the tables in our Oracle database that have attributes
I have a table in Oracle database with field with data type CLOB .
I have two columns(column1, column2) in my oracle database table named as demo .

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.