Oracle获得范围数字

时间:2013-11-18 10:07:09

标签: sql oracle plsql

这是我的连续表:

+-----------------+-----------------+
|  START_SERIAL   |   END_SERIAL    |
+-----------------+-----------------+
| 120500216057150 | 120500216057155 |
| 120500216057157 | 120500216057157 |
| 120500216057161 | 120500216057164 |
+-----------------+-----------------+

需要得到这样的结果:

120500216057150 
120500216057151 
120500216057152 
120500216057153 
120500216057154 
120500216057155
120500216057157
120500216057161....

请帮我解决这个问题。 [似乎需要带有for循环的pl-sql。?]

修改 亲爱的TechDo, 那么pl / sql的用法如下所示。但是它给了我一个错误: - )

DECLARE
  start_serial  NUMBER;
  end_serial  NUMBER;
  records NUMBER;
BEGIN
  select start_serial INTO start_serial
    from sales_details ;
  select (start_serial+no_of_cards)as end_serial into end_serial
    from sales_details;
  select count(*) as records into records 
    from sales_details;

  FOR i IN 1..records  LOOP
    INSERT INTO temp (serial_no)
    VALUES(i);
  END LOOP;
END;
/

1 个答案:

答案 0 :(得分:5)

请尝试:

select 
  distinct START_SERIAL+level-1 SERIAL
from 
  YourTable
connect by level-1<=END_SERIAL-START_SERIAL
order by 1;