What is a Slowly Changing Dimension?
- Although dimension tables are typically static lists, most dimension tables do change over time.
- Since these changes are smaller in magnitude compared to changes in fact tables, these dimensions are known as slowly growing or slowly changing dimensions.
- Slowly changing dimensions are classified into three different types
- TYPE I
- TYPE II
- TYPE 11 -Version Control
- TYPE 11- Flag Control
- TYPE 11 - Date Control
- TYPE III
Slowly Changing Dimension 2(SCD2) - Version Control
Process :
Step 1: Create Source Table & Data
- We can use Scott Schema EMP table
- Import table using source analyzer
Step 2: Create Target Table
- Create target table in target database
CREATE TABLE EMP_SCD2_VERSION
( EMPKEY NUMBER(5,0) PRIMARY KEY,
EMPNO NUMBER(5,0),
ENAME VARCHAR2(20 BYTE),
JOB VARCHAR2(20 BYTE),
SAL NUMBER(10,2),
DEPTNO NUMBER(5,0),
VERSION NUMBER(5)
)
|
- Import table using Target Designer
Step 3: Create mapping with transformations
- Create a mapping with the name m_SCD2_VERSION
- Drag and drop source and target into work area
- Introduce Lookup transformation and select lookup table as EMP_SCD2_VERSION
- Drag and drop EMPNO from Source Qualifier to Lookup and rename it as EMPNO_in
- Click on condition tab of lookup provide join condition as shown below
- Click on properties tab and select multiple match property as last value
- Introduce Expression transformation into work area and name it as exp_INSERT_UPDATE_NOCHANGE
- Drag and drop ports EMPNO,ENAME,JOB,SAL,DEPTNO from source qualifier to expression
- Drag and drop ports EMPKEY,JOB,SAL,VERSION from Lookup to expression and rename job,sal,version as job_previous ,sal_previous,version_previous respectively
- Add one new port in expression and name it as INSERT_UPDATE_NOCHANGE_FLAG
- Develop expression using below formula
IIF(
ISNULL(EMPKEY),'I',
IIF(
(JOB != JOB_previous) OR
(SAL != SAL_previous),'U','NC' ) )
|
- Introduce ROUTER transformation → Drag and drop EMPNO,ENAME,JOB,SAl,DEPTNO,INSERT_UPDATE_NOCHANGE_FLAG and VERSION_previous from expression to router
- Double click on ROUTER header → click on groups tab → add a group as shown
- Introduce Expression transformation→ from INSERT section of router drag and drop ports EMPNO1,ENAME1,JOB1,SAL1,DEPTNO1,VERSION_previous1 and INSERT_UPDATE_NOCHANGE_FLAG1
- Create two new ports EMPKEY ,VERSION
- Introduce Sequence generator transformation and connect NEXTVAL with EMPKEY
- develop below expression in version port
- Overall it looks like below
- Introduce update strategy transformation and connect as shown
- Connect ports from update strategy transformation to target as shown
- save it
Step 4: Create Workflow and Session
- Create workflow and session as shown below
- Double click on session task provide source and target connection accordingly
- Save the workflow
Step 5: Run workflow and Observe output
- Observe source data in my case
- Select Start task → click on run
- observe target data
- Observe target table output
- Update any one existing record in my case iam updating RAM REDDY sal from 8000 to 10000
- Run Workflow again
Step 6: Download workflow XML Code and observe it
No comments:
Post a Comment