首页 > 数据库 > mysql教程 > Oracle创建时间维度

Oracle创建时间维度

WBOY
发布: 2016-06-07 15:32:27
原创
1056 人浏览过

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

相关标签:
来源:php.cn
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板