/  3
 
SET SERVEROUTPUT ONSET LINESIZE 300COLUMN TARIFF_NAME FORMAT A20COLUMN START_DATE FORMAT A19COLUMN END_DATE FORMAT A19DROP TABLE src_tariff_plan;DROP TABLE dim_tariff;DROP SEQUENCE seq_tariff_key;CREATE TABLE src_tariff_plan (tariff_code NUMBER(4),tariff_name VARCHAR2(200),tariff_shname VARCHAR2(6),currency_id NUMBER(5),tariff_group_id NUMBER(2) ); CREATE TABLE dim_tariff (tariff_key NUMBER(6),tariff_code NUMBER(4),tariff_name VARCHAR2(200),tariff_shname VARCHAR2(6),currency_id NUMBER(5),tariff_group_id NUMBER(2),start_date DATE,end_date DATE,current_record CHAR(1),CONSTRAINT pk_dim_tariff PRIMARY KEY (tariff_key) ); CREATE SEQUENCE seq_tariff_key;INSERT INTO src_tariff_plan VALUES ( 5011, 'Tariff 1', 'TAR01', 0, 1 );INSERT INTO src_tariff_plan VALUES ( 5021, 'Tariff 2', 'TAR02', 0, 1 );INSERT INTO src_tariff_plan VALUES ( 5031, 'Tariff 3', 'TAR03', 0, 2 );COMMIT;DECLAREnew_records NUMBER(9);ver_records NUMBER(9);ovw_records NUMBER(9);BEGINupdate_scd( pSrcTable => 'SRC_TARIFF_PLAN',pNaturalKey => 'TARIFF_CODE',pTrgTable => 'DIM_TARIFF',pSurrogateKey => 'TARIFF_KEY',pSequence => 'SEQ_TARIFF_KEY',pOverwriteCols => 'CURRENCY_ID,TARIFF_GROUP_ID',pVersionedCols => 'TARIFF_NAME,TARIFF_SHNAME',pStartTS => 'START_DATE',pEndTS => 'END_DATE',pCurrRecFlag => 'CURRENT_RECORD',pNewRecordsCount => new_records,pVersionedRecordsCount => ver_records,pOverwrittenRecordsCount => ovw_records);dbms_output.put_line('New records: '  new_records  ', versioned records:'  ver_records  ', overwritten records: '  ovw_records );END;/
 
 SELECT tariff_key,tariff_code,tariff_name,tariff_shname,currency_id,tariff_group_id,to_char(start_date,'yyyy-mm-dd hh24:mi:ss') start_date,to_char(end_date,'yyyy-mm-dd hh24:mi:ss') end_date,current_recordFROM dim_tariffORDER BY tariff_code,start_date;INSERT INTO src_tariff_plan VALUES ( 5041, 'Tariff 4', 'TAR04', 1, 2 );INSERT INTO src_tariff_plan VALUES ( 5051, 'Tariff 5', 'TAR05', 2, 3 );UPDATE src_tariff_planSET tariff_name = 'First tariff'WHERE tariff_code = 5011;UPDATE src_tariff_planSET currency_id=99WHERE tariff_code = 5021; UPDATE src_tariff_planSET tariff_shname = 'TARX03',tariff_group_id = 88WHERE tariff_code = 5031; COMMIT;DECLAREnew_records NUMBER(9);ver_records NUMBER(9);ovw_records NUMBER(9);BEGINupdate_scd( pSrcTable => 'SRC_TARIFF_PLAN',pNaturalKey => 'TARIFF_CODE',pTrgTable => 'DIM_TARIFF',pSurrogateKey => 'TARIFF_KEY',pSequence => 'SEQ_TARIFF_KEY',pOverwriteCols => 'CURRENCY_ID,TARIFF_GROUP_ID',pVersionedCols => 'TARIFF_NAME,TARIFF_SHNAME',pStartTS => 'START_DATE',pEndTS => 'END_DATE',pCurrRecFlag => 'CURRENT_RECORD',pNewRecordsCount => new_records,pVersionedRecordsCount => ver_records,pOverwrittenRecordsCount => ovw_records);dbms_output.put_line('New records: '  new_records  ', versioned records:'  ver_records  ', overwritten records: '  ovw_records );END;/SELECT tariff_key,tariff_code,tariff_name,tariff_shname,currency_id,tariff_group_id

Share & Embed

More from this user

Recent Readcasters

Add a Comment

Characters: ...