Oracle
 sql >> Datenbank >  >> RDS >> Oracle

Erstellen eines CTE in Oracle

Sie können Ihren gemeinsamen Tabellenausdruck (CTE, Unterabfrage-Factoring usw.) erstellen, indem Sie die Datumswerte von dual auswählen und sie alle zusammenführen:

with RTG_YEARS (YR) as (
  select to_date('2013-01-01', 'yyyy-mm-dd') from dual
  union all select to_date('2013-12-31', 'yyyy-mm-dd') from dual
  union all select to_date('2014-01-01', 'yyyy-mm-dd') from dual
  union all select to_date('2014-12-31', 'yyyy-mm-dd') from dual
  union all select to_date('2015-01-01', 'yyyy-mm-dd') from dual
  union all select to_date('2015-12-31', 'yyyy-mm-dd') from dual
)
select * from RTG_YEARS;

YR       
----------
2013-01-01
2013-12-31
2014-01-01
2014-12-31
2015-01-01
2015-12-31

Hat nichts damit zu tun, dass es sich um einen CTE handelt, aber Sie können die Eingabe etwas reduzieren, indem Sie Datumsliterale verwenden:

with RTG_YEARS (YR) as (
  select date '2013-01-01' from dual
  union all select date '2013-12-31' from dual
  union all select date '2014-01-01' from dual
  union all select date '2014-12-31' from dual
  union all select date '2015-01-01' from dual
  union all select date '2015-12-31' from dual
)
select * from RTG_YEARS;