首頁 >資料庫 >mysql教程 >Oracle创建时间维度

Oracle创建时间维度

WBOY
WBOY原創
2016-06-07 15:32:271059瀏覽

SQL Scripts to create Date Dimension in Oracle. Create Table SQL: CREATE TABLE Date_D( DateKey Integer NOT NULL, DateValue Date NOT NULL, Day Char(10 ), DayOfWeek Integer, DayOfMonth Integer, DayOfYear Integer, PreviousDay date, NextDay da

SQL Scripts to create Date Dimension in Oracle.

Create Table SQL:

CREATE TABLE Date_D(<br> DateKey Integer NOT NULL,<br> DateValue Date NOT NULL,<br> Day Char(10 ),<br> DayOfWeek Integer,<br> DayOfMonth Integer,<br> DayOfYear Integer,<br> PreviousDay date,<br> NextDay date,<br> WeekOfYear Integer,<br> Month Char(10 ),<br> MonthOfYear Integer,<br> QuarterOfYear Integer,<br> Year Integer<br> )

SQL To populate the table:

INSERT INTO Date_D<br> SELECT<br> to_number(to_char(CurrDate, 'YYYYMMDD')) as DateKey,<br> CurrDate AS DateValue,<br> TO_CHAR(CurrDate,'Day') as Day,<br> to_number(TO_CHAR(CurrDate,'D')) AS DayOfWeek,<br> to_number(TO_CHAR(CurrDate,'DD')) AS DayOfMonth,<br> to_number(TO_CHAR(CurrDate,'DDD')) AS DayOfYear,<br> CurrDate - 1 as PreviousDay,<br> CurrDate + 1 as NextDay,<br> to_number(TO_CHAR(CurrDate+1,'IW')) AS WeekOfYear,<br> TO_CHAR(CurrDate,'Month') AS Month,<br> to_number(TO_CHAR(CurrDate,'MM')) AS MonthofYear,<br> to_number((TO_CHAR(CurrDate,'Q'))) AS QuarterOfYear,<br> to_number(TO_CHAR(CurrDate,'YYYY')) AS Year<br> FROM (<br> select level n, TO_DATE('31/12/2009','DD/MM/YYYY') + NUMTODSINTERVAL(level,'day') CurrDate<br> from dual<br> connect by level order by 1

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn