with
test_data (account_nmbr, term) as (
select 'ABC200', 6 from dual union all
select 'DEF100', 8 from dual
)
-- End of simulated inputs (for testing purposes only, not part of the solution).
-- SQL query begins BELOW THIS LINE.
select level as row_nmbr, term, account_nmbr
from test_data
connect by level <= term
and prior account_nmbr = account_nmbr
and prior sys_guid() is not null
order by account_nmbr, row_nmbr -- If needed
;
ROW_NMBR TERM ACCOUNT_NMBR
-------- ---------- ------------
1 6 ABC200
2 6 ABC200
3 6 ABC200
4 6 ABC200
5 6 ABC200
6 6 ABC200
1 8 DEF100
2 8 DEF100
3 8 DEF100
4 8 DEF100
5 8 DEF100
6 8 DEF100
7 8 DEF100
8 8 DEF100
In Oracle 12, können Sie die LATERAL
Klausel für die gleiche verwenden:
with
test_data (account_nmbr, term) as (
select 'ABC200', 6 from dual union all
select 'DEF100', 8 from dual
)
-- End of simulated inputs (for testing purposes only, not part of the solution).
-- SQL query begins BELOW THIS LINE.
select l.row_nmbr, t.term, t.account_nmbr
from test_data t,
lateral (select level as row_nmbr from dual connect by level <= term) l
order by account_nmbr, row_nmbr -- If needed
;
Was Version Ihrer Datenbank? (Wie 12.1.0.2.0) Wenn Sie nicht sicher wissen, wählen Sie * aus v $ version. Verschiedene Antworten sind in verschiedenen Versionen der Datenbank verfügbar. – mathguy
Bitte formatieren Sie Text [nicht Bilder] (https://meta.stackoverflow.com/questions/285551/why-not-upload-images-of-code-on-so-when-asking-a-question/285557# 285557). –
Oracle-Version: 11g Enterprise Edition Version 11.2.0.3. – DieHard345