Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

oracle date sequence?

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

like image 722
Hoax Avatar asked Jan 18 '10 12:01

Hoax


1 Answers

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>
like image 92
APC Avatar answered Nov 10 '22 16:11

APC