SQL 中的日历表 [英] Calendar table in SQL

查看:117
本文介绍了SQL 中的日历表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在 oracle SQL 中创建一个包含单列日期数据类型的表,该表包含从 2000 年 1 月 1 日到今天的所有日子

How to create a table that contains a single column of date data type, that consists of all days starting from Jan 1, 2000 until today in oracle SQL

推荐答案

您可以使用 Oracle 行生成器:

 insert into your_table ( your_column )
 select 
    to_date('2000/01/01', 'yyyy/mm/dd') + N.n
 from
  (SELECT ROWNUM n
   FROM   ( SELECT 1 just_a_column
         FROM   dual
         CONNECT BY LEVEL <= 
               SYSDATE
               - to_date('2000/01/01', 'yyyy/mm/dd') 
               + 1
           ) T
  ) N
  where
      to_date('2000/01/01', 'yyyy/mm/dd') + N.n <= SYSDATE

这篇关于SQL 中的日历表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆