ORACLE SQL:Get all integers between two numbers

前端 未结 13 1286
说谎
说谎 2020-12-03 13:42

Is there any way to select the numbers (integers) that are included between two numbers with SQL in Oracle; I don\'t want to create PL/SQL procedure or function.

Fo

13条回答
  •  情话喂你
    2020-12-03 14:09

    I want to share an usefull query that converts a string of comma and '-' separated list of numbers into a the equivalent expanded list of numbers:

    An example that converts '1,2,3,50-60' into

    1
    2
    3
    50
    51
    ...
    60
    
    select distinct * from (SELECT (LEVEL - 1) + mini as result FROM (select REGEXP_SUBSTR (value, '[^-]+', 1, 1)mini ,nvl(REGEXP_SUBSTR (value, '[^-]+', 1, 2),0) maxi from (select REGEXP_SUBSTR (value, '[^,]+', 1, level) as value from (select '1,2,3,50-60' value from dual) connect by level <= length(regexp_replace(value,'[^,]*'))+1)) CONNECT BY Level <= (maxi-mini+1)) order by 1 asc;
    

    You may use it as a view and parametrize the '1,2,3,50-60' string

提交回复
热议问题