Using Oracle 11g, and working in an engineering document context, I need to select a collection of rows that include 'extra' rows for prior revs and multiple document sheets.
Specifically, our database has a record for only the latest revision of each engineering document. We need a row returned for each revision and each sheet of these records.
We have data like this:
DRAW_NUM REV NUM_SHTS
LD-111-639-01 2 3
We Need Data Like This:
DRAW_NUM REV SHT
LD-111-639-01 1 1
LD-111-639-01 1 2
LD-111-639-01 1 3
LD-111-639-01 2 1
LD-111-639-01 2 2
LD-111-639-01 2 3
My latest SQLPlus query attempt uses an external table to list numbers from 0 to Rev and 0 to Num_Shts, and the code looks like this:
SELECT DISTINCT prefix || '-' || lpad(series,3,0) || '-' || lpad(base,3,0) || '-' || lpad(suffix,2,0) Draw_Num,
(select n from numbers where n >=0 and n <= md_draw.rev) Rv,
(select n from numbers where n >=0 and n <= md_draw.num_shts) Sht
FROM md_draw WHERE Dwg_Date <= TO_DATE('1-JUN-02')
ORDER BY Draw_Num, Rv, Sht
/
But produces the following error:
ORA-01427: single-row subquery returns more than one row
Is there an easy way to do this?