Slowly Changing Dimension 2(SCD2) - Flag 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_FLAG
( 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),
FLAG VARCHAR2(1)
)
|
- Import table using Target Designer
Step 3: Create mapping with transformations
- Create a mapping with the name m_SCD2_FLAG
- Drag and drop source and target into work area
- Introduce Lookup transformation and select lookup table as EMP_SCD2_FLAG
- 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 from Lookup to expression and rename job,sal as job_previous ,sal_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 EMPKEY,EMPNO,ENAME,JOB,SAL,DEPTNO and INSERT_UPDATE_NOCHANGE_FLAG from expression to router
- Double click on ROUTER header → click on groups tab → add two groups as shown
- Introduce Expression transformation→ from INSERT section of router drag and drop ports EMPNO1,ENAME1,JOB1,SAL1,DEPTNO1and INSERT_UPDATE_NOCHANGE_FLAG1
- Create two new ports EMPKEY1 ,FLAG
- Introduce Sequence generator transformation and connect NEXTVAL with EMPKEY1
- Provide constant value ‘Y’ in FLAG port
- Overall it looks like below
- Introduce update strategy transformation and connect as shown
- Connect ports from update strategy transformation to target as shown
- Introduce Expression and update strategy transformations
- Duplicate target table and connect all as shown
- Double click on update strategy transformation → provide Update Strategy Expression as 1
- 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 10000 to 12000
- Run Workflow again
Step 6: Download workflow XML Code and observe it
https://drive.google.com/file/d/0B6mKqi53iP-NOWdtaDFvRW1zMEU/edit?usp=sharing