Saturday, April 23, 2016

Opposite to ListAgg Function

Example: (single Record)
 Single record 'Trinesh,Shanthi,Tejesh,Vasavi' need to convert into 4 records as follows
Trinesh
Shanthi
Tejesh
Vasavi 
using simple SQL query.

Query:
SELECT REGEXP_SUBSTR('Trinesh,Shanthi,Tejesh,Vasavi','[^,]+',1,LEVEL) NAMES FROM DUAL
CONNECT BY LEVEL <= LENGTH(REGEXP_REPLACE('Trinesh,Shanthi,Tejesh,Vasavi','[^,]+'))+1

Example: (Multiple Record)

Source:

 Query:




ListAgg Example

Example:
How to display department_id and corresponding employees name delimited with ',' operator?

For Example:
Data looks as follows:

We need to convert above data as follow:


Query:

SELECT DEPARTMENT_ID , 
LISTAGG(FIRST_NAME||'.'||LAST_NAME,', ') WITHIN GROUP (ORDER BY FIRST_NAME) EMPLOYEE_LIST FROM HR.EMPLOYEES
GROUP BY DEPARTMENT_ID;

Saturday, December 12, 2015

PIVOT in ODI 12c

How to Implement PIVOT component in ODI 12c?

Scenario:
To avoid redundant data

Scripts:

CREATE TABLE STUDENT_LOC(
SNAME VARCHAR2(30),
PREFERENCE VARCHAR2(20),
LOCATION VARCHAR2(20));

INSERT INTO STUDENT_LOC VALUES('TRINESH','LOCATION1','HYDERABAD');
INSERT INTO STUDENT_LOC VALUES('TRINESH','LOCATION2','BANGALORE');
INSERT INTO STUDENT_LOC VALUES('SHANTHI','LOCATION1','HYDERABAD');
INSERT INTO STUDENT_LOC VALUES('SHANTHI','LOCATION2','BANGALORE');
INSERT INTO STUDENT_LOC VALUES('BAPI','LOCATION1','HYDERABAD');
INSERT INTO STUDENT_LOC VALUES('BAPI','LOCATION2','USA');
INSERT INTO STUDENT_LOC VALUES('RAJU','LOCATION1','USA');
INSERT INTO STUDENT_LOC VALUES('RAJU','LOCATION2','BANGALORE');
INSERT INTO STUDENT_LOC VALUES('DEEPAK','LOCATION1','DUBAI');
INSERT INTO STUDENT_LOC VALUES('DEEPAK','LOCATION2','HYDERABAD');
COMMIT;

CREATE TABLE STUDENT_LOCATION (
SNAME VARCHAR2(30),
LOCATION1 VARCHAR2(20),
LOCATION2 VARCHAR2(20));
/

Steps to Implement:
1.     Create new Mapping
2.     Drag and drop source datastore(STUDENT_LOC) and target datastore from model(STUDENT_LOCATION )
3.     Drag and drop Pivot component from component palette into mapping editor
4.     Connect output connector of PIVOT to input connector of Target datastore
It will pop up as below:



Enable checkbox “Create Attributes On Source” and “Auto Map” and click on OK.
5.     Connect output connector of source datastore to input connector of Pivot Component
6.     Disable checkbox “Create Attributes on Target”
7.     Select Pivot component and go to property inspector
8.     For Sname under expression select “Sname” from source datastore
Row Locator: Select “Preference” Column from source Datastore
Click ok “+” symbol to create ROW Locator values
“LOCATION1”
“LOCATION2”
Under “Matching row” for LOCATION1 column in pivot component select “LOCATION1” and for expression select “Location” Column
Under “Matching row” for LOCATION2 column in pivot component select “LOCATION2” and for expression select “Location” Column
It looks as below:
 
9.     Select appropriate knowledge module in physical tab by selecting target datastore (IKM Oracle insert.Global by default it will comes, you can leave as it)
10. Execute Mapping
Output & Flow:



ORA-12560: TNS:protocol adaptor error

How to resolve TNS: Protocol Adaptor Error

1. Go Start --> Run
2. Enter services.msc
3. Start below services

  • OracleMTSRecoveryService
  • OracleServiceXE
  • OracleXEClrAgent
  • OracleXETNSListener
4. Now try to reconnect. It will resolve your issue.

Sunday, November 15, 2015

UNPIVOT ODI 12C

UNPIVOT ODI 12C
Scripts:
CREATE TABLE SALES(
YEAR          VARCHAR2(4) ,
Q1      NUMBER(10,2) ,
Q2     NUMBER(10,2) ,
Q3      NUMBER(10,2) ,
Q4      NUMBER(10,2) );
/
CREATE TABLE SALES_PER_QUARTER(
YEAR VARCHAR2(4),
QUARTER VARCHAR2(2),
SALES NUMBER(10,2));
/
INSERT INTO SALES VALUES('2014',23345.32,32456.41,21234.21,18324.12);
INSERT INTO SALES VALUES('2015',24324.12,34234.51,25345.18,17234.86);
COMMIT;
/

Steps:
1.       Create new Mapping
2.       Drag and drop Source datastore and target datastore
3.       Drag and drop unpivot component from component palette into Mapping editor
4.       Connect UNPIVOT and target datastore and select as below screen

5.       Click ok
6.       Now connect source datastore and UNPIVOT component and deselect the create attributes on Target
7.       Select unpivot component and go to property inspector (Ctrl+Shift+i)
8.       Select Row Locator as Quarter under – General tab
9.       Click on “+” symbol and add four columns as below


10.   Execute the mapping
11.   Output:



Completed Successfully!!!!

Saturday, November 14, 2015

Unable to Reverse Engineering Synonym in ODI 12c

Unable to Reverse Engineering Synonym in ODI 12c


Issue:
We can able to see the Synonym but after Reverse Engineer structure of datastore is empty

     Steps to be the followed to fix:

1. Check your Logical Schema and context for that model

2. Logical Schema will be available in overview tab of model and context will be available under Reverse Engineer Tab of the model

3.Go to Topology Navigator then Logical Architecture  and check logical schema for that particular context and find out your data Server (for eg: xyz.abc that means xyz is Data Server and abc is Physical Schema)

4.In the physical Architecture, go to Data server and then properties tab and add the following:
"key= includeSynonyms and value= true"

5.Now you are able to perform Reverse Engineer for synonym !!!!!!!!

Thursday, September 10, 2015

How to implement un-pivot concept in ODI 11g


SQL Scripts used in Demo:
CREATE TABLE SALES(
YEAR          VARCHAR2(4) ,
Q1      NUMBER(10,2) ,
Q2     NUMBER(10,2) ,
Q3      NUMBER(10,2) ,
Q4      NUMBER(10,2) );
/
CREATE TABLE SALES_PER_QUARTER(
YEAR VARCHAR2(4),
QUARTER VARCHAR2(2),
SALES NUMBER(10,2));
/
INSERT INTO SALES VALUES('2014',23345.32,32456.41,21234.21,18324.12);
INSERT INTO SALES VALUES('2015',24324.12,34234.51,25345.18,17234.86);
COMMIT;
/

Scenario
In this scenario, we are converting rows into columns.
Implementing un-pivot component which is available in ODI 12c (which will be available from 12.1.3 version onwards) in ODI 11g

Process:
1.      Create model
2.      Create Reverse engineer above mention datastores
3.      Create new interface
4.      Drag and drop Source datastore (SALES) and Target Datastore (SALES_PER_QUARTER)
As mention below and map accordingly.

5.      Click on “highlighted” dataset symbol (in the above diagram) which will pop-up for datasets creation.
6.      Create four datasets for four quarters as below.

7.      Now interface looks as follows

8.      For Quarter2 –Quarter Column ‘Q2’ and Sales Column <Q2_Value>
Similarly we need to repeat for Quarter3 and Quarter4
9.      Make sure that Quarter mapping should be “Staging”
10.  Select appropriate knowledge as per your requirement (In this case I am selecting IKM SQL Control Append) and flow control as “false” (because I don’t have any key on target side)
11.  Execute it.

Output: