数据库里建一个如图时间表,该怎么建?下面的数据又该怎么插入?求代码

0

1487914459(1).jpg

current_month :插入1-12月,current_quarter:插入1-4季度,current_year:插入1998-2017年,day_cap:插入1998年1月1日-2017年1月1日,day_date:1998-01-01 0:00:00 - 2017-12-31 0:00:00,dAY_key :19980101.00 - 20171231.00 ,day_of_month:1-31天,Day_of_week:1-7周,day_of_year:1-365天,days_in_month :28-31天,month_CAP:1998年01月-2017年12月,month_en:(英文)1-12月,month_key:199801-201712,month_number:1-12,month_sc:一月-十二月,
quarter_key:19981.00-201712.00,week_of_month:1-5,week_of_quarter:1-14,week_of_year:1-53,weekday_en:(英文)周一-周五,weekday_sc:星期一到xin星期日
已邀请:
1

老头子 - 专注是唯一的捷径 2017-02-24 回答

create table 维表名字
as 
select pdate,to_char(pdate,'MM') as current_month,to_char(pdate,'Q') as current_quarter,
to_char(pdate,'YYYY') as current_year,
to_char(pdate,'yyyy"年"mm"月"dd"日"') as day_cap,
pdate as day_date,
to_char(pdate,'yyyymmdd')||'.00' as dAY_key,
to_char(pdate,'DD') as day_of_month ,
to_char(pdate,'D') as Day_of_week,
to_char(pdate,'DDD') as day_of_year,
trunc(last_day(pdate))-trunc(pdate,'MM')+1 as days_in_month,
to_char(pdate,'yyyy"年"mm"月"') as month_CAP,
to_char(pdate,'month','NLS_DATE_LANGUAGE = American') as month_en,
to_char(pdate,'yyyymm') as month_key,
to_char(pdate,'mm') as month_number,
to_char(pdate,'month','NLS_LANGUAGE = CHINESE.ZHS16GBK') as month_sc,
to_char(pdate,'yyyy')||to_char(pdate,'Q')||'.00' as quarter_key,
to_char(pdate,'W') as week_of_month,
'没有这样的函数自己拼吧' as week_of_quarter,
to_char(pdate,'WW') as week_of_year,
to_char(pdate,'Day','NLS_DATE_LANGUAGE = American') as weekday_en,
to_char(pdate,'Day','NLS_LANGUAGE = CHINESE.ZHS16GBK') as weekday_sc
from (select level,(trunc(sysdate) - 6995) + level as pdate
from dual connect by level <= to_date('2017-12-31','yyyy-mm-dd') - to_date('1998-01-01','yyyy-mm-dd'))
0

GeorgeYao - 路漫漫其修远兮,吾将上下而求索! 2017-02-24 回答

这是一张时间维表,只不过有十几个维度
create table  DateDim(
current_month int
.......
)
 
和普通的表设计没有什么 区别,主要在于维度的多少。

要回复问题请先登录注册