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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T06:50:34+00:00 2026-05-14T06:50:34+00:00

I need to convert a list of numbers that fall within certain ranges into

  • 0

I need to convert a list of numbers that fall within certain ranges into a list of values, ordered by a priority column. The table has the following values:

| YEAR | R_MIN |  R_MAX | VAL | PRIO |
------------------------------------
  2010   18000    90100   52    6
  2010  240000   240099   82    3
  2010  250000   259999   50    5
  2010  260000   260010   92    1
  2010  330000   330010   73    4
  2010  330011   370020   50    5
  2010  380000   380050   84    2

The ranges will be different for different years. The ranges within one year will never overlap.

The input will be a year and a list of numbers that might fall within one these ranges. The list of input number will be small, 1 to 10 numbers. Example of input numbers:

(20000, 240004, 375000, 255000)

With that input I would like to get a list ordered by the priority column, or a single value:

82
50
52

The only value I’m interested in here is 82, so UNIQUE and MAX_RESULTS=1 would do. It can easily be done with one query per number, and then sorting it in the Java code, but I would prefer to do it in a single SQL query.

What SQL query, to be run in an Oracle database, would give me the desired result?

(Note, this is not about splitting an input string, it’s about matching each value in a list of values to ranges defined in different columns.)

  • 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-14T06:50:34+00:00Added an answer on May 14, 2026 at 6:50 am

    I am guessing you want to pass that set of numbers as a string and split into into individual numbers. This is harder than you might think, because Oracle doesn’t come with a built-in tokenizer. Weird, huh?

    There are a number of PL/SQL tokenizer solutions knocking around Das Interwabs. I am using a variant of Anup Pani’s implementation, which uses Regex (hence only Oracle 10g or higher). My variant returns an array of numbers which I have declared as a SQL type:

    SQL> create or replace type numbers as table of number
      2  /
    
    Type created.
    
    SQL>
    

    This means I can use it as an input to a TABLE() function in a SELECT statement:

    SQL> select * from table (str_to_number_tokens('20000, 240004, 375000, 255000'))
      2  /
    
    COLUMN_VALUE
    ------------
           20000
          240004
          375000
          255000
    
    SQL>
    

    This means I can turn your string of numbers into a table which I can join to in a query, like this:

    SQL> select val
      2  from t23
      3       , ( select column_value as i_no
      4           from table (str_to_number_tokens('20000, 240004, 375000, 255000')) ) sq
      5  where t23.year = 2010
      6  and   sq.i_no between t23.r_min and t23.r_max
      7  order by t23.priority
      8  /
    
           VAL
    ----------
            82
            50
            52
    
    SQL>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to convert a list (or a dict) into a comma-separated list for
I need convert some Mac Numbers(00163e2fbab7) into Mac String. (with :) Is there some
I need to convert from an integer to a list of size 8 that
I need to convert the following collection into double[,]: var ret = new List<double[]>();
I need to convert latitude/longitude coordinates into Easting/Northing coordinates in the Alberta 10 TM
I need to convert HTML documents into valid XML, preferably XHTML. What's the best
I need to convert a value which is in a DateTime variable into a
I need to convert a Word document into HTML file(s) in Java. The function
I need to perform some calculations a large list of numbers. Do array.array or
I want to convert a List to a List so that each object on

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.