Previous_month_first_day:
TO_CHAR
(
SET_DATE_PART
(
ADD_TO_DATE(sysdate,'MM',-1),
'DD',
1
)
, 'DD.MM.YYYY'
)
Previous_month_last_day:
TO_CHAR(
LAST_DAY( ADD_TO_DATE(sysdate,'MM',-1) )
,
'DD.MM.YYYY'
)
31 Ekim 2013 Perşembe
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.
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:
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.
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
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
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 ) )
TO_CHAR( TO_NUMBER( COLUMN_A ) )
Kaydol:
Kayıtlar (Atom)











