Oracle创建时间维度

WBOY
WBOYオリジナル
2016-06-07 15:32:271064ブラウズ

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 までご連絡ください。