CREATE
TABLE
D_TIME(
d_time date,
dim_year varchar2 ( 4 ),
dim_quarter varchar2 ( 6 ),
dim_month varchar2 ( 6 ),
dim_day varchar2 ( 9 ));
DECLARE
begin_date date;
end_date date;
BEGIN
begin_date : = to_date( ' 2007-01-01 ' , ' yyyy-mm-dd ' );
end_date : = to_date( ' 2007-12-31 ' , ' yyyy-mm-dd ' );
LOOP
INSERT INTO D_TIME(d_time)
VALUES (begin_date);
begin_date : = begin_date + 1 ;
EXIT WHEN begin_date > end_date;
END LOOP;
COMMIT ;
END ;
UPDATE D_TIME SET dim_year = to_char(d_time, ' yyyy ' );
UPDATE D_TIME SET dim_quarter = to_char(d_time, ' yyyy ' ) || ' 0 ' || to_char(d_time, ' q ' );
UPDATE D_time SET dim_month = to_char(d_time, ' yyyy ' ) || to_char(d_time, ' mm ' );
UPDATE D_TIME SET dim_day = to_char(d_time, ' yyyy ' ) || to_char(d_time , ' mm ' ) || to_char(d_time, ' dd ' );
COMMIT ;
d_time date,
dim_year varchar2 ( 4 ),
dim_quarter varchar2 ( 6 ),
dim_month varchar2 ( 6 ),
dim_day varchar2 ( 9 ));
DECLARE
begin_date date;
end_date date;
BEGIN
begin_date : = to_date( ' 2007-01-01 ' , ' yyyy-mm-dd ' );
end_date : = to_date( ' 2007-12-31 ' , ' yyyy-mm-dd ' );
LOOP
INSERT INTO D_TIME(d_time)
VALUES (begin_date);
begin_date : = begin_date + 1 ;
EXIT WHEN begin_date > end_date;
END LOOP;
COMMIT ;
END ;
UPDATE D_TIME SET dim_year = to_char(d_time, ' yyyy ' );
UPDATE D_TIME SET dim_quarter = to_char(d_time, ' yyyy ' ) || ' 0 ' || to_char(d_time, ' q ' );
UPDATE D_time SET dim_month = to_char(d_time, ' yyyy ' ) || to_char(d_time, ' mm ' );
UPDATE D_TIME SET dim_day = to_char(d_time, ' yyyy ' ) || to_char(d_time , ' mm ' ) || to_char(d_time, ' dd ' );
COMMIT ;