Joiner Transformation in Informatica PowerCenter - Trouble in joining duplicate values from source with target - informatica-powercenter

I have following scenario
Source 1: Category_DTL
Category_ID Date Value
1 20180101 10
1 20180110 12
2 20180101 14
3 20180101 15
4 20180101 10
Source 2: Category_Master
Category_ID Name Comments
1 abc C1
2 xyz C2
3 qwe C3
4 rty C4
5 qqq C5
6 www C6
I need output as:
Category_ID Date Value Name Comments
1 20180101 10 abc C1
1 20180110 12 abc C1
2 20180101 14 xyz C2
3 20180101 15 qwe C3
4 20180101 10 rty C4
But When I use joiner transformation in Informatica PowerCenter, I get following output:
Category_ID Date Value Name Comments
1 20180101 10 abc C1
1 20180110 12
2 20180101 14 xyz C2
3 20180101 15 qwe C3
4 20180101 10 rty C4
It only matches first record from source with master table in case source have duplicate values on key column used in joining condition.
Join conditon > Category_Master.Category_ID = Category_DTL.Category_ID
Join type used > Detail outer Join
Master Table > Category_Master
Detail Table > Category_DTL
Any suggestion to get desired result is appreciated.

Related

PIVOT using AVG not working correctly in my query

I have following table and finding difficult to produce expected output. I have tried following query but it doesn't produce correct 'AVG' using 'PIVOT'. The average value should show in respective columns of category as per the output. In my below query it doesn't work
SELECT *
FROM (select avg(hd.SCORE) over(partition by hd.org_id) Avg_Item
, hd.org_id,d.cateogory,hd.score FROM Category d JOIN Assign hd ON d.catid=hd.catid) first
PIVOT (
AVG(score)
FOR (cateogory)
IN ('cat1' as "cat1",'cat2' as "cat2",'cat3' as "cat3",'cat4' as "cat4")
)PIV;
Sample Tables & Expected Output
Category table
-----------------------
catid cateogory
1 cat1
2 cat2
3 cat3
4 cat4
5 cat5
Assign table
--------------------------
Aid(pk) catid(fk) pid Score org_id
1 1 1 98 1
2 1 2 99 1
3 1 3 100 1
4 2 4 12 4
5 2 8 78 5
6 5 9 98 6
org Table
-----------------------------
org_id org_name
1 ABC
2 CDE
3 FGH
4 Google
5 Yahoo
6 Facebook
Desired output
----------------------------------
org_name cat1 cat2 cat3 cat4 cat5
ABC 99
CDE 12
FGH
Google 78
Yahoo 98
Facebook
Assuming score is actually a number, not a string like 98%, then your current query seems to work, and (with cat5 added) produces:
AVG_ITEM
ORG_ID
cat1
cat2
cat3
cat4
cat5
99
1
99
null
null
null
null
12
4
null
12
null
null
null
78
5
null
78
null
null
null
98
6
null
null
null
null
98
which seems right.
But you aren't using the analytic avg_item you calculate in your desired result, so you can remove that form the subquery. And you can outer join the result of the pivot to the org table to get the organisation names:
SELECT o.org_name, p.cat1, p.cat2, p.cat3, p.cat4, p.cat5
FROM org o
LEFT JOIN (
SELECT *
FROM (
SELECT hd.org_id, d.cateogory, hd.score
FROM Category d
JOIN Assign hd ON d.catid=hd.catid
)
PIVOT (
AVG(score)
FOR (cateogory)
IN ('cat1' as cat1, 'cat2' as cat2, 'cat3' as cat3, 'cat4' as cat4, 'cat5' as cat5)
)
) p
ON p.org_id = o.org_id
ORDER BY o.org_id;
or more simply:
SELECT o.org_name, p.cat1, p.cat2, p.cat3, p.cat4, p.cat5
FROM (
SELECT hd.org_id, d.cateogory, hd.score
FROM Category d
JOIN Assign hd ON d.catid=hd.catid
)
PIVOT (
AVG(score)
FOR (cateogory)
IN ('cat1' as cat1, 'cat2' as cat2, 'cat3' as cat3, 'cat4' as cat4, 'cat5' as cat5)
) p
RIGHT JOIN org o
ON o.org_id = p.org_id
ORDER BY o.org_id;
which both get:
ORG_NAME
CAT1
CAT2
CAT3
CAT4
CAT5
ABC
99
null
null
null
null
CDE
null
null
null
null
null
FGH
null
null
null
null
null
Google
null
12
null
null
null
Yahoo
null
78
null
null
null
Facebook
null
null
null
null
98
fiddle
Your expected result seems to have the wrong values against the organisations (or the wrong IDs in the org table), but other than that, this seems to be your desired result.

Update one column of each row in a table [PL/SQL, unix scripting]

i have a table with 12 columns:
table1:
1
2
3
4
5
6
7
8
9
10
11
12
abc
1
000
aaa
zzz
2
234
OOO
00001
01
123
214
def
2
023
bbb
yyy
4
345
PPP
00002
02
133
224
ghi
3
011
ccc
xxx
6
456
QQQ
00003
03
143
234
jkl
4
112
ddd
www
8
567
RRR
00004
04
153
244
i would like to use 3rd column data in a loop and fetch 'best match' data from another table.
table2:
1
2
3
4
0
777
676
america
00
888
878
england
01
999
989
france
02
666
656
germany
3rd column data will be trimmed in the loop until a match in table2 is fetched.
first row:
iter 1: table1 row1 col3=000 -- no match in table
iter 2: table1 row1 col3=00 -- return england, replace table1 row1 col12=214 with 'england'
updated row: abc,1,000,aaa,zzz,2,234,OOO,00001,01,123,england
second row:
iter 1: table1 row2 col3=023 -- no match in table
iter 2: table1 row2 col3=02 -- return germany, replace table1 row1 col12=224 with 'germany'
updated row: def,2,023,bbb,yyy,4,345,PPP,00002,02,133,germany
What you will need to do is create a procedure, then within the procedure declare a cursor as well as a variable_c_row cursor_name%ROWTYPE.
Within the procedure, this will be the contents:
OPEN cursor_name
FETCH cursor_name INTO variable_c_row;
WHILE cursor_name%FOUND LOOP
-- Declare a number variable (i)
i := 0;
-- Declare a varchar variable (match)
match := variable_c_row.col3
WHILE length(match) > 0 LOOP OR l_countryname IS NULL
begin
-- Declare a yourrow%ROWTYPE variable (l_countryname)
SELECT col4 FROM table2 INTO l_countryname WHERE col1 = match;
UPDATE table1 SET col12 = l_countryname;
exception when no_data_found then null;
end;
i := i+1;
match := substr(variable_c_row.cow3, 0, length(match)-i);
END LOOP;
FETCH cursor_name INTO variable_c_row;
END LOOP;
CLOSE cursor_name;
Since the question had no DDL or DML, the most I can provide is a broad answer, which has not been tested.

How to Join four Tables?

I need to join three tables into the sale table, I tried left join but it does not join properly. can you guys plz give a solution.
Sale Tabel
MSISSND Agent_ID Connection_Date District
3455 22 22-Jan-2020 abc
1222 22 12-Feb-2020 abc
4562 25 23-Feb-2020 zxy
8907 23 12-Mar-2020 rty
Agent Tabel
Agent_ID Agent_name Distributor_ID Distributor_name
22 nikon 12 A-Z
23 cannon 13 tech
25 hp 14 hp-tech
Customer Tabel
MSISSND Name Address
3455 nilak adcd
4562 suman sdfg
8907 nizar ewrt
1222 rowan fgsk
Target Tabel
Distributor_ID District Month Target
12 abc Jan_2020 10
12 abc Feb_2020 15
13 rty Feb_2020 20
14 zxy Mar_2020 24
Output_final table will be
MSISSND Agent_Id Agent_name Conection_Date Connection_MON_YEAR District Distributor_ID Distibutor_name Target Name Address
3455 22 nikon 22-Jan-2020 Jan-2020 abc 12 A-Z 10 nilak adcd
You have not given us anything about the data types or the constraints you are using. You may also want to look at the normalization and the business rules again. (But maybe that's something to ask in another question)
However, you could do something like:
select
S.msissnd
, A.agentid, A.agentname
, to_char( S.connectiondate, 'DD-Mon-YYYY' ) as Connection_Date
, to_char( T.month_, 'Mon-YYYY' ) as Connection_MON_YEAR
, T.district, T.distributorid
, A.distributorname
, T.target
, C.name_, C.address
from sale S
join agent A on S.agentid = A.agentid
join customer C on S.msissnd = C.msissnd
join target T on A.distributorid = T.distributorid
and to_char( S.connectiondate, 'MM' ) = to_char( T.month_, 'MM' )
;
-- result
MSISSND AGENTID AGENTNAME CONNECTION_DATE CONNECTION_MON_YEAR DISTRICT DISTRIBUTORID DISTRIBUTORNAME TARGET NAME_ ADDRESS
__________ __________ ____________ __________________ ______________________ ___________ ________________ __________________ _________ ________ __________
3455 22 nikon 22-Jan-2020 Jan-2020 abc 12 A-Z 10 nilak adcd
1222 22 nikon 12-Feb-2020 Feb-2020 abc 12 A-Z 15 rowan fgsk
DBfiddle here.
If the "Month" in your TARGET table is a VARCHAR2() type, you could add a virtual column containing a date, so you don't need to write an explicit conversion into your query.
-- eg
SQL> alter table target
2 add when_ date generated always as (
3 to_date( Month, 'MON_YYYY')
4 ) virtual ;

Tracking missing records between migrated tables in oracle

I have a table called TABLE1 as follow
ID | SP_NUMBER |CATEGORY
------------------------
1 101 A
2 101 B
3 101 C
4 102 A
5 102 B
6 103 A
7 103 C
suppose I migrated above table data to new table called TABLE2
ID | SP_NUMBER |CATEGORY
------------------------
1 101 A
2 101 C
3 102 A
4 102 B
5 103 C
Note that , after the migration TABLE2 missing some records. I want genarelise way to track those missing data
as a example I need to show
101 B
103 A
are not migrated.
Use MINUS
select sp_number,category FROM TABLE1 MINUS
SELECT sp_number,category from TABLE2;
Demo

Oracle - Tree - PL/SQL - Copying data with mapping

I have following table structure
ID Name Parent_ID
1 abc 0
2 efg 1
3 hij 1
4 klm 2
5 nop 3
and so on....id is generated in a sequence
I want a PL/SQL to coy this same data in same table but id should be generated by seq and Parent_ID should be mapped accordingly...that means..after PL/SQL it should look like
ID Name Parent_ID
1 abc 0
2 efg 1
3 hij 1
4 klm 2
5 nop 3
6 abc 0
7 efg 6
8 hij 6
9 klm 7
10 nop 8
can any1 help me in this...thnx
So, here is your original data:
SQL> select * from t23
2 /
ID NAM PARENT_ID
---------- --- ----------
1 abc 0
2 efg 1
3 hij 1
4 klm 2
5 nop 3
SQL>
This procedure populates a PL/SQL collection with the extant rows. It loops through those rows, populating an associative array with a new ID which is indexed by the original ID. (Note the assignment uses the 11g syntax for getting a sequence value, rather than the traditional selecting from DUAL). The ID is then chnaged to the new value, and the PARENT_ID is updated with the value stored in the associative array. Lastly the new rows are inserted into the table using the bulk FORALL syntax,
SQL> declare
2 type num_lookup is table of pls_integer
3 index by pls_integer;
4 id_translate num_lookup;
5
6 type t23_nt is table of t23%rowtype;
7 new_rows t23_nt;
8 begin
9 select *
10 bulk collect into new_rows
11 from t23
12 order by id asc;
13
14 for i in new_rows.first()..new_rows.last()
15 loop
16 id_translate(new_rows(i).id) := s23.nextval;
17 new_rows(i).id := s23.currval;
18 if new_rows(i).parent_id != 0
19 then
20 new_rows(i).parent_id := id_translate(new_rows(i).parent_id);
21 end if;
22 end loop;
23
24 forall j in new_rows.first()..new_rows.last()
25 insert into t23 values new_rows(j);
26
27 end;
28 /
PL/SQL procedure successfully completed.
SQL>
And, lo!
SQL> select * from t23;
ID NAM PARENT_ID
---------- --- ----------
1 abc 0
2 efg 1
3 hij 1
4 klm 2
5 nop 3
6 abc 0
7 efg 6
8 hij 6
9 klm 7
10 nop 8
10 rows selected.
SQL>

Resources