I have the same query listed as subquery multiple times within a larger Oracle SQL query. Is there a way to define it once and reuse it using a shorter form?
1 Answer
You can make use of common table expressions.
Copied query from here: Creating a CTE in Oracle
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
cross join RTG_YEARS;
1 Comment
Punter Vicky
Thank you very much , @Evaldas!