在Oracle中创建CTE

在Oracle中创建CTE,第1张

在Oracle中创建CTE

您可以通过从对偶中选择日期值并将它们结合在一起来创建公用表表达式(CTE,子查询分解等)。

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-012013-12-312014-01-012014-12-312015-01-012015-12-31

与CTE无关,但是您可以通过使用日期文字来减少输入:

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;


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5011169.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-11-15
下一篇 2022-11-15

发表评论

登录后才能评论

评论列表(0条)

保存