SQL Query to return N rows from dual

前端 未结 10 2023
盖世英雄少女心
盖世英雄少女心 2021-02-13 10:31

I want to write a SQL query which accepts a bind variable (say :NUM) and its output consists of one column & :NUM number of rows, each row having its row number. i.e. if we

10条回答
  •  萌比男神i
    2021-02-13 11:09

    Another way is to use an XQuery range expression, e.g.:

    select column_value from xmltable(:a||' to '||:b);
    
     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    

    This solution is quite flexible, e.g.:

    select column_value from xmltable('5 to 10, 15 to 20');
    
     5
     6
     7
     8
     9
    10
    15
    16
    17
    18
    19
    20
    

提交回复
热议问题