歡迎來到我的部落格!
在公司裡,日曆表及相關引數必定是極其重要的,它的準確性影響著整個業務,隨著業務的複雜,獲取各種奇葩日期可能往往會耗費很大精力。
一、基礎日曆表、日期參數列建立
表結構圖示:
基礎日曆表:
日期參數列:
建表語句:
- 建立基礎日曆表
--建立基礎日曆表
-- Create table
create table SCOTT.D_DATE
(
date_code NUMBER(8) not null,
date_desc VARCHAR2(30 CHAR),
wk_of_year_code NUMBER(8),
wk_of_year_lbl VARCHAR2(10 CHAR),
wk_of_year_desc VARCHAR2(30 CHAR),
mth_code NUMBER(8),
mth_lbl VARCHAR2(10 CHAR),
mth_desc VARCHAR2(30 CHAR),
quar_code NUMBER(8),
quar_lbl VARCHAR2(10 CHAR),
quar_desc VARCHAR2(30 CHAR),
six_months_code NUMBER(8),
six_months_desc VARCHAR2(30 CHAR),
year_code NUMBER(8),
year_desc VARCHAR2(30 CHAR),
wk_start_flag VARCHAR2(30 CHAR),
wk_end_flag VARCHAR2(30 CHAR),
mth_start_flag VARCHAR2(30 CHAR),
mth_end_flag VARCHAR2(30 CHAR),
quar_start_flag VARCHAR2(30 CHAR),
quar_end_flag VARCHAR2(30 CHAR),
year_start_flag VARCHAR2(30 CHAR),
year_end_flag VARCHAR2(30 CHAR),
trd_daily_flag CHAR(1 CHAR),
etl_date TIMESTAMP(6),
hkex_trd_daily_flag CHAR(1 CHAR),
hgt_trd_daily_flag CHAR(1 CHAR)
);
-- Add comments to the table
comment on table SCOTT.D_DATE
is '日期維表';
-- Add comments to the columns
comment on column SCOTT.D_DATE.date_code
is '日期程式碼';
comment on column SCOTT.D_DATE.date_desc
is '日期描述';
comment on column SCOTT.D_DATE.wk_of_year_code
is '年中周程式碼';
comment on column SCOTT.D_DATE.wk_of_year_desc
is '年中周描述';
comment on column SCOTT.D_DATE.mth_code
is '月份程式碼';
comment on column SCOTT.D_DATE.mth_desc
is '月份描述';
comment on column SCOTT.D_DATE.quar_code
is '季程式碼';
comment on column SCOTT.D_DATE.quar_desc
is '季描述';
comment on column SCOTT.D_DATE.six_months_code
is '半年程式碼';
comment on column SCOTT.D_DATE.six_months_desc
is '半年描述';
comment on column SCOTT.D_DATE.year_code
is '年程式碼';
comment on column SCOTT.D_DATE.year_desc
is '年描述';
comment on column SCOTT.D_DATE.wk_start_flag
is '周初標誌';
comment on column SCOTT.D_DATE.wk_end_flag
is '週末標誌';
comment on column SCOTT.D_DATE.mth_start_flag
is '月初標誌';
comment on column SCOTT.D_DATE.mth_end_flag
is '月末標誌';
comment on column SCOTT.D_DATE.quar_start_flag
is '季初標誌';
comment on column SCOTT.D_DATE.quar_end_flag
is '季末標誌';
comment on column SCOTT.D_DATE.year_start_flag
is '年初標誌';
comment on column SCOTT.D_DATE.year_end_flag
is '年末標誌';
comment on column SCOTT.D_DATE.trd_daily_flag
is '交易日標誌';
comment on column SCOTT.D_DATE.etl_date
is 'ETL日期';
comment on column SCOTT.D_DATE.hkex_trd_daily_flag
is '港交所交易日標誌';
comment on column SCOTT.D_DATE.hgt_trd_daily_flag
is '滬股通交易日標誌';
-- Create/Recreate primary, unique and foreign key constraints
alter table SCOTT.D_DATE
add constraint PK_D_DATE primary key (DATE_CODE)
using index ;
- 日期參數列
--建立參數列
-- Create table
create table SCOTT.DATE_VARIABLE_PARAMETER
(
txdate NUMBER(8) not null,
variable_code VARCHAR2(50) not null,
variable_name VARCHAR2(50) not null,
variable_descr VARCHAR2(100),
variable_value VARCHAR2(100)
);
-- Add comments to the table
comment on table SCOTT.DATE_VARIABLE_PARAMETER
is '日期參數列';
-- Add comments to the columns
comment on column SCOTT.DATE_VARIABLE_PARAMETER.txdate
is '執行日期';
comment on column SCOTT.DATE_VARIABLE_PARAMETER.variable_code
is '變數程式碼';
comment on column SCOTT.DATE_VARIABLE_PARAMETER.variable_name
is '變數名稱';
comment on column SCOTT.DATE_VARIABLE_PARAMETER.variable_descr
is '變數描述';
comment on column SCOTT.DATE_VARIABLE_PARAMETER.variable_value
is '變數值';
-- Create/Recreate primary, unique and foreign key constraints
alter table SCOTT.DATE_VARIABLE_PARAMETER
add constraint PK_DATE_VARIABLE_PARAMETERPK_ primary key (TXDATE, VARIABLE_CODE);
二、日期資料插入基礎日曆表
詳細步驟如下:
sql語句如下:
--sql語句
SELECT DATE_CODE
,TRD_DAILY_FLAG
,HKEX_TRD_DAILY_FLAG
,HGT_TRD_DAILY_FLAG
FROM SCOTT.D_DATE
FOR UPDATE;
繼續操作
下載基礎日曆表資料excel
下載地址(堅果雲):
點選下載
開啟excel進行繼續如下操作
!!!選擇commit提交資料後,查詢結果表是否有資料,若提示是否將改變的記錄寫入資料庫,選擇是。
謝謝閱讀!
本作品採用《CC 協議》,轉載必須註明作者和本文連結