更新时间:2022-10-15 12:03:31
如果你想要的是填充一连串日期的记录块,这很容易做。以下查询生成十个日期。所有您需要做的是调整种子日期,以便您通过子句在连接中为您提供起点和
级别
符合您的终点,然后将其插入插入
语句。
SQL>选择(trunc(sysdate,'MM') - 1)+级
2从双
3连接级别< = 10
4 /
(TRUNC (SY
---------
01-JAN-10
02-JAN-10
03-JAN-10
04-JAN- 10
05-JAN-10
06-JAN-10
07-JAN-10
08-JAN-10
09-JAN-10
10-JAN-10
选择10行
SQL>
I have an oracle db and I need a table containing all the dates spanning 2 years;
for example from 01/01/2011
to 01/01/2013
.
First I thought of a sequence but apparently the only supported type is number, so now I am looking for an efficient way to do this
cheers hoax
If what you want is to populate a block of records with sequential dates, that is easy enough to do. The following query generates ten dates. All you need to do is adjust the seed date to give you your starting point and the level
in the connect by
clause to fit your end point, and then plug it into an insert
statement.
SQL> select (trunc(sysdate, 'MM')-1) + level
2 from dual
3 connect by level <= 10
4 /
(TRUNC(SY
---------
01-JAN-10
02-JAN-10
03-JAN-10
04-JAN-10
05-JAN-10
06-JAN-10
07-JAN-10
08-JAN-10
09-JAN-10
10-JAN-10
10 rows selected.
SQL>