ORACLE SQL:Get all integers between two numbers

前端 未结 13 1290
说谎
说谎 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:05

    SQL> var N_BEGIN number
    SQL> var N_END number
    SQL> exec :N_BEGIN := 3; :N_END := 10
    
    PL/SQL procedure successfully completed.
    
    SQL>  select :N_BEGIN + level - 1 n
      2     from dual
      3  connect by level <= :N_END - :N_BEGIN + 1
      4  /
    
             N
    ----------
             3
             4
             5
             6
             7
             8
             9
            10
    
    8 rows selected.
    

    This uses the same trick as Tony's. Note that when you are using SQL*Plus 9, you have to make this query an inline view as Tony showed you. In SQL*Plus 10 or higher, the above is sufficient.

    Regards, Rob.

提交回复
热议问题