>데이터 베이스 >MySQL 튜토리얼 >Oracle创建时间维度

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으로 문의하세요.