我是维度建模的新手,因为它有点卡住了。情景是'公司'已将其假期保险和疾病保险的填写外包给他们填写的代理机构,每个填写的会话称为班次。我有一个4维表格如下。为简单起见,我只包括一行。我使用的是sql开发人员
公司维度 - 包含公司分支机构的所有详细信息
BranchId|BranchName|Postcode|County
12 |Kensington|rt5gg |newengland
Shift_worker维度 - 包含填充工作人员的所有详细信息
worker_id|worker_name|phone
33 |Steve Smith|07766755543
Shift_request维度 - 包含公司向代理商提出的请求的所有详细信息
Request_id|Branch_id
1221 |12
Time_dimension
time_id|week_num|day_of_the_week|quarter_num|weekend_flag|Year
221 |3 | 3 |2 |N |2014
最后是转换表,事实表将从中读取
shift_date |shift_status|shift_id|request_id|worked_hours|type
------------------------------------------------------------------
09-01-2011|Filled |8899 |1221 | 2 |cleaner
21-01-2011 |Cancelled |6677 |1332 | 0 |Admin_assistant
我创建了一个事实表,如下所示
CREATE TABLE "FACT_company"
( "FACT_ID" NUMBER,
"TIME_ID" NUMBER,
"BRANCH_ID" NUMBER,
"WORKER_ID" NUMBER,
"REQUEST_ID" NUMBER,
"SHIFT_ID" NUMBER,
"WORKED_HOURS" NUMBER,
"TYPE" VARCHAR2(30 BYTE),
"SHIFT_STATUS" VARCHAR2(30 BYTE)
) SEGMENT CREATION DEFERRED
PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255
NOCOMPRESS LOGGING
TABLESPACE "COMPANY" ;
如何在PL / SQL中使用游标填充此事实?我的目的是分析之后的数据,找出每个月取消了多少班次,每季度填写了多少班次等等。我希望自己走在正确的道路上。
答案 0 :(得分:2)
我已将shift_table
的两列添加为WorkerId int
和timeId int
,并在以下策略中使用适当的值填充它们:
SQL> create table Company_dimension( BranchId int, BranchName varchar2(50), Postcode varchar2(15), County varchar2(50));
SQL> insert into Company_dimension values(12,'Kensington','rt5gg','newengland');
SQL> create table Shift_worker_dimension( worker_id int, worker_name varchar2(50) , phone varchar2(15) );
SQL> insert into Shift_worker_dimension values(33,'Steve Smith','07766755543');
SQL> create table Shift_request_dimension( Request_id int, Branch_id int);
SQL> insert into Shift_request_dimension values(1221,12);
SQL> create table Time_dimension( time_id int, week_num int, day_of_the_week int, quarter_num int, weekend_flag varchar2(1),Year int );
SQL> insert into Time_dimension values(221,3,3,2,'N',2014);
SQL> create table Shift_table( shift_date date, shift_status varchar2(25), shift_id int, request_id int, worked_hours int, type varchar2(25), WorkerId int, timeId int );
SQL> insert into shift_table values(to_date('09-01-2011','dd-mm-yyyy'),'Filled',8899,1221,2,'cleaner',33,221);
SQL> insert into shift_table values(to_date('21-01-2011','dd-mm-yyyy'),'Cancelled',6677,1332,0,'Admin_assistant',null);
SQL> create table fact_company(FACT_ID NUMBER, TIME_ID NUMBER, BRANCH_ID NUMBER, WORKER_ID NUMBER, REQUEST_ID NUMBER, SHIFT_ID NUMBER, WORKED_HOURS NUMBER, TYPE VARCHAR2(30 BYTE), SHIFT_STATUS VARCHAR2(30 BYTE) );
SQL> create sequence seq_fact start with 1;
SQL> insert into fact_company
select seq_fact.nextval,
td.time_id,
cd.branchid,
sw.worker_id,
sr.request_id, st.shift_id, st.worked_hours, st.type, st.shift_status
from Shift_table st
join Shift_request_dimension sr on (sr.request_id = st.request_id)
join Company_dimension cd on ( sr.branch_id = cd.branchid )
join Shift_worker_dimension sw on (sw.worker_id = st.workerid)
join Time_dimension td on (td.time_id = st.timeid);
SQL> commit;