From the table:
| name | range |
------------------------
| 'Range1' | '456-458' |
| 'Range2' | '11-13' |
just trying to get this result:
| name | range | value |
--------------------------------
| 'Range1' | '456-458' | 456 |
| 'Range1' | '456-458' | 457 |
| 'Range1' | '456-458' | 458 |
| 'Range2' | '11-13' | 11 |
| 'Range2' | '11-13' | 12 |
| 'Range2' | '11-13' | 13 |
made the query which works fine if the source table has only one range:
WITH data AS (
SELECT 'Range1' name, '456-458' range FROM dual
)
SELECT ROWNUM, name, range, LEVEL value
FROM data, dual
WHERE LEVEL >= to_number(SUBSTR(range, 1, INSTR(range,'-')-1))
CONNECT BY LEVEL <= to_number(SUBSTR(range, INSTR(range,'-')+1));
but returns tens of thousands of rows, if takes two ranges:
WITH data AS (
SELECT 'Range1' name, '456-458' range FROM dual
UNION
SELECT 'Range2' name, '11-13' range FROM dual
)
SELECT ROWNUM, name, range, LEVEL value FROM data, dual
WHERE LEVEL >= to_number(SUBSTR(range, 1, INSTR(range,'-')-1))
CONNECT BY LEVEL <= to_number(SUBSTR(range, INSTR(range,'-')+1));
Is it possible to improve this query to get the required, or my approach is wrong initially?
Oracle Database 11g Express Edition Release 11.2.0.2.0 - 64bit Production
in 11g you can use a recursive factored sub query for this type of thing.