How to populate a calendar table in Oracle?

I want to save the calendar table in the Oracle database, which I want to fill with all the years of the year, starting from 2011 to 2013 (this can be up to any year). How can i do this?

Consider that there are columns and an example data set in my DB table:

S.No  Cal_Dt      DayName 
1     01-01-2011  Monday
2     02-01-2011  Tuesday
3     03-01-2011  Wednesday

etc.

I'm only more interested in Cal_Dt (DayName is optional).

+5
source share
4 answers

This is a simple and easy way to do it.

with calendar as (
        select :startdate + rownum - 1 as day
        from dual
        connect by rownum < :enddate - :startdate
    )
select rownum as "S.No", to_date(day,'dd_mm_yyyy') as "Cal_Dt", to_char(day,'day') as "DayName"
from calendar
+12
source
declare
  v_date date := to_date('20110101','yyyymmdd');
begin

   while v_date < sysdate + 720 loop

      insert into calender
      values ( v_date, to_char(v_date,'DAY'));

      v_date := v_date + 1;

   end loop;
   commit;

end;
/

, Allesandro Rossi. , Oracle 9i .

+2
with calendar as (
        select rownum - 1 as daynum
        from dual
        connect by rownum < sysdate - to_date('1-jan-2010') + 1
    )
select to_date('1-jan-2010') + daynum as monthdate
from calendar
;
+2
with calendar as (
        select :startdate + rownum - 1 as day
        from dual
        connect by rownum < :enddate - :startdate
    )
select rownum as "S.No", to_date(day,'dd_mm_yyyy') as "Cal_Dt", to_char(day,'day') as "DayName"
from calendar

12? . - ?

0

Source: https://habr.com/ru/post/1652046/


All Articles