Home >Database >Mysql Tutorial >Oracle创建时间维度

Oracle创建时间维度

WBOY
WBOYOriginal
2016-06-07 15:32:271059browse

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

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn