0

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 1

4

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;
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you very much , @Evaldas!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.