26 Ekim 2013 Cumartesi

ODI Knowledge Module For UPDATE WITHOUT EXISTS OR IN CLAUSE

Hi

In this case i will show how to get rid of exists check over update sql statement and i will explain a knowledge module that impelements following kind of sql statement.

Enviroment : Oracle DB  & ODI 11g

Case Study:
I have an employee_list table which contains basic information about employees and now i want to make an update over job title which also triggers update over his or her salary and region information.

EMPLOYEE_LIST:
CREATE TABLE REPORTING.EMPLOYEE_LIST
(
EMP_ID NUMBER,
NAME VARCHAR2(100 CHAR),
SALARY  NUMBER,
TITLE_ID NUMBER,
LOCATION_ID NUMBER
)









TABLES USED FOR UPDATE:
CREATE TABLE REPORTING.EMPLOYEE_UPDATE
(
EMP_ID NUMBER,
SALARY  NUMBER, 
TITLE_ID  NUMBER,
LOCATION_ID  NUMBER
)











CREATE TABLE REPORTING.EMPLOYEE_TITLE
(
TITLE_ID NUMBER,
TITLE  VARCHAR2(100 CHAR)
)













CREATE TABLE REPORTING.EMPLOYEE_LOCATION
(
LOCATION_ID NUMBER,
REGION  VARCHAR2(100 CHAR),
CITY    VARCHAR2(100 CHAR)
)










Normally sql statement should be like this:

UPDATE  REPORTING.EMPLOYEE_LIST 
SET( SALARY  ,  TITLE_ID  ,   LOCATION_ID  )= 
(

select EMPLOYEE_LIST.SALARY +  EMPLOYEE_UPDATE.SALARY  AS SALARY_1 ,
       EMPLOYEE_UPDATE.TITLE_ID  AS TITLE_ID_1 , EMPLOYEE_UPDATE.LOCATION_ID  AS LOCATION_ID_1  
       from REPORTING.EMPLOYEE_LIST   EMPLOYEE_LIST, REPORTING.EMPLOYEE_LOCATION   EMPLOYEE_LOCATION, 
       REPORTING.EMPLOYEE_TITLE   EMPLOYEE_TITLE, REPORTING.EMPLOYEE_UPDATE   EMPLOYEE_UPDATE   
       where 1=1  And (EMPLOYEE_LIST.EMP_ID=EMPLOYEE_UPDATE.EMP_ID) 
       AND (EMPLOYEE_LIST.TITLE_ID=EMPLOYEE_TITLE.TITLE_ID) AND (EMPLOYEE_LIST.LOCATION_ID=EMPLOYEE_LOCATION.LOCATION_ID) 
)
WHERE  EMPLOYEE_LIST.EMP_ID IN
(
      select  EMPLOYEE_UPDATE.EMP_ID
       from REPORTING.EMPLOYEE_LIST   EMPLOYEE_LIST, REPORTING.EMPLOYEE_LOCATION   EMPLOYEE_LOCATION, 
       REPORTING.EMPLOYEE_TITLE   EMPLOYEE_TITLE, REPORTING.EMPLOYEE_UPDATE   EMPLOYEE_UPDATE   
       where 1=1  And (EMPLOYEE_LIST.EMP_ID=EMPLOYEE_UPDATE.EMP_ID) 
       AND (EMPLOYEE_LIST.TITLE_ID=EMPLOYEE_TITLE.TITLE_ID) AND (EMPLOYEE_LIST.LOCATION_ID=EMPLOYEE_LOCATION.LOCATION_ID)   
)

This statement can work but  we have to read each table twice so it is not costly efficient approach.

Instead i did like this:

 UPDATE 
 ( 
       select EMPLOYEE_LIST.SALARY  ,EMPLOYEE_LIST.TITLE_ID  ,EMPLOYEE_LIST.LOCATION_ID  , EMPLOYEE_LIST.SALARY +  EMPLOYEE_UPDATE.SALARY  AS SALARY_1 ,
       EMPLOYEE_UPDATE.TITLE_ID  AS TITLE_ID_1 , EMPLOYEE_UPDATE.LOCATION_ID  AS LOCATION_ID_1  
       from REPORTING.EMPLOYEE_LIST   EMPLOYEE_LIST, REPORTING.EMPLOYEE_LOCATION   EMPLOYEE_LOCATION, 
       REPORTING.EMPLOYEE_TITLE   EMPLOYEE_TITLE, REPORTING.EMPLOYEE_UPDATE   EMPLOYEE_UPDATE   
       where 1=1  And (EMPLOYEE_LIST.EMP_ID=EMPLOYEE_UPDATE.EMP_ID) 
       AND (EMPLOYEE_LIST.TITLE_ID=EMPLOYEE_TITLE.TITLE_ID) AND (EMPLOYEE_LIST.LOCATION_ID=EMPLOYEE_LOCATION.LOCATION_ID)     
 )   TRG     
SET  TRG.SALARY = SALARY_1, TRG.TITLE_ID = TITLE_ID_1,
TRG.LOCATION_ID = LOCATION_ID_1

------------------------------------------------------------------------------------------------
Like this no need to EXISTS or IN clause 

Note: In this approach our lookup tables has to have PRIMARY_KEYS which are

TITLE_ID  FOR  EMPLOYEE_TITLE
LOCATION_ID  FOR EMPLOYEE_LOCATION
EMP_ID  FOR    EMPLOYEE_UPDATE
 
Otherwise we will face  non-preserved key  error.


-------------------------------------------------------------------------------

Now I am gonna Implement this update statement over ODI , at first i am creating an interface like a normal select - Insert  script.( i am createing inner select statement which i specified above ) 
( Target table is used in both source and target part of the mapping)


















In target mapping for the Columns , which do not be used in statement , update and insert flags has to be set to uncheck. In my example  EMP_ID and NAME should be look like this:

















For the ones ( SALARY , TITLE_ID , LOCATION_ID)  which will be used in update statement look like this:  ( update flag is checked )


















and i choose the KM i wrote 


















For detail you can download the KM from the link below.


After Execution  view of EMP_LIST table as follows:







29 Eylül 2013 Pazar

KNOWLEDGE MODULE EXECUTE IMMEDIATE AND LOG TABLE

In this entry i will show you how to create your own log table mechanism inside of ODI. Also i will use EXECUTE IMMEDIATE ( package like approach) in this knowledge module. As an example i am gonna using IKM Knowlege Module for Oracle DB

Environment : ODI 11g , Oracle 10g database


Step1: I create a log table in Oracle Db

CREATE TABLE  DUMMY
(
INTERFACE_ID   NUMBER, -- interface_id  ( interface based uniqueID given by ODI)
SESSION_NO   NUMBER,    --  ( session_based uniqueID given by ODI can be used as PK)
INTERFACE_NAME  VARCHAR2( 500 CHAR),  -- name of the interface
QUERY   LONG,   -- query that suppose to be run inside of ODI knowledge Module
AFFECTED_NOF_ROWS NUMBER, -- affected nof rows after query execution
RUN_START_DATE  date,  -- execution start_date
RUN_END_DATE  date,  -- execution end_date
STATUS  NUMBER  -- 0 for fails   1 for success
)

Step2: I created a dummy interface and choose the Knowledge Module I wrote
(IKM SQL Control Append LogTable) which is a version of IKM SQL Control Append.





































IKM SQL Control Append LogTable : This knowlege module basically has an Oracle package body kind of script.Only different thing that i did is to combine oracle coding with odi methods such as getsession , getInterfaceID etc..

For detail about script you can download KM from the link below:
http://speedy.sh/wT5Dm/KM-IKM-SQL-Control-Append-LogTable.xml

Step3: After execution completed by sample log table as follows:





10 Eylül 2013 Salı

Informatica Load Into table with Index Error : WRT-8229 ORA-26002: Table string has index defined upon it

Solution:
Change TARGET_LOAD_TYPE from BULK to Normal  ( Workflow-->Session-->Mapping  )
it will work fine , or you can drop indexes and run with bulk mode too.

27 Ağustos 2013 Salı

Oracle SUBSTRING USING SPECIFIC CHARACTER

Just combine two function as follows.

Example:

SELECT SUBSTR('ABCD_EFG', 0, INSTR(TABLE_NAME, '_')-1) AS output
FROM dual

Result:
ABCD

18 Ağustos 2013 Pazar

Oracle - Date Conversion Sample

For those who always needs :

 SELECT TO_CHAR(TO_DATE('19981215','YYYYMMDD'),'YYYY' )  FROM DUAL  --Result  1998
   
 SELECT TO_CHAR(TO_DATE('19981215','YYYYMMDD'),'MM' )  FROM DUAL    --Result  12
   
 SELECT TO_CHAR(TO_DATE('19981215','YYYYMMDD'),'DD' )  FROM DUAL     --Result  15

Oracle - Trim Leading Zeros

*Assuming the data you are working on is CHARACTER :

TO_CHAR( TO_NUMBER( COLUMN_A ) )

16 Temmuz 2013 Salı

ODI Knowledge Module for UNION , UNION_ALL, INTERSECT

Hi all

In this entry , i will explain how to make UNION , UNION_ALL, INTERSECT style operations without making extra insertion or temp table creation.


 *Case : What i want to do is to gather all employee information which currently holds in different tables.
 ( Tested enironment : Oracle 10g database , ODI 11g )

 At first we will create a table which holds the SQLs for final statement.

CREATE TABLE REPORTING.INTERFACE_QUERY
 (

INTERFACE_NAME VARCHAR2(2000 BYTE),
EXE_SCRIPT LONG

 )


 * This table contains two columns ,one interface name which holds the name of the interface and  EXE_SCRIPT which holds the SQL created by ODI interface.

*What we gonna do is  to extract source tables called EMPLOYEE_PRE , EMPLOYEE_VICE_PRE, EMPLOYEE_PRG  and fill them into a table called EMPLOYEE_ALL


*Now creating  interfaces which are their target tables are dummy ( yellow interfaces )


















* In this interface we will add EMPLOYEES who are currently presidents and with the help of  IKM knowledge module called  IKM SQL Control Append-SubQuery

Link for Download
http://rapidshare.com/files/815556971/KM_IKM_SQL_Control_Append_SubQuery.xml

SQL statement which is created by the interface will be inserted into REPORTING.INTERFACE_QUERY table.Same operation will be done for vice president and programmer tables .

As a result we have following data in our reference table ( Interface_Query ) and we have 3 temp interface.















*Now what we have to do create a main interface which gathers all sql statements above and  load data into our target table.

*I will prepare the allignment of the columns for my target table which has to be matched with my subquery columns.

Before:












After:













Then i created a new interface called Interface_main. Mapping looked like this









* I drag 3 temp interfaces as a source and in order to maintain integrity  connecting them with dummy join ( department_name )  and adding my target table with mappings ( those mapping added as dummy too )

* now i am assigning the knowledge module  called  IKM SQL Control Append-Union-Minus-Intersect-Union All

Link for Download
http://rapidshare.com/files/1050531261/KM_IKM_SQL_Control_Append_Union_Intersect_Union_All.xml

*Parameters for this Knowledge Module look like this

















*Basically  knowledge module  gathers SQL statements from REPORTING.INTERFACE_QUERY  and depends on the parameter we choose, it makes UNION , UNION ALL or INTERSECT and creates a resultset which load into our target table. As a result following sql statement has been created and executed.



















*