Scenario 1:
Source Table:
Expected Result:
Using Pivot keyword:
Scenario 1:
Source Table:
Expected Result:
Using Pivot keyword:
Scenario's:
1. I have an employee table 4 of them are male candidates and 4 of them are female candidates. I need result in such a way that alternatively I have to show male and female employees
Employee Table:
Output:
2. I have Table A (Driving Table) and Table B (Lookup table).I have to pick all the values from Table-A
but if I came across any duplicates when I join with Table-B then I have to pick only one value from Table-B.
For Example:
Table A(Employee):
Table B(Department):
Expected Result:
Query:
select name,department_name from (
select e.name,d.name department_name,row_number() over (partition by rn order by d.name) rn from
(select name,department_id,rownum rn from employee) e left outer join department d on e.department_id = d.department_id)
where rn=1
Output:
Let me take a scenario:
I have implemented SCD 3 type in ODI 12c using Customized knowledge Module. Before using it I want to check it out whether is working as per requirement or not.
Source Data:
Q: You want to ensure that the Physical Mapping Design cannot be modified even if the Logical Design of the Mapping is changed. What sequence of steps must you follow to achieve this
Ans:
Q: You need to create a Model that works with multiple underlying technologies. How must you proceed?
Ans: Create a new generic technology to support it.
From ODI 12c onwards we can load multiple tables with single mapping. In that case we need to make sure that which table need to be load first and next. For that we need to specify order.
In ODI, we have option of specify join order.
Scripts |
Source: [ { "id":
"0001", "type":
"donut", "name":
"Cake", "ppu":
0.55, "batters": { "batter": [ {
"id": "1001", "type": "Regular" }, {
"id": "1002", "type": "Chocolate" }, {
"id": "1003", "type": "Blueberry" }, {
"id": "1004", "type": "Devil's Food"
} ] }, "topping": [ {
"id": "5001", "type": "None" }, {
"id": "5002", "type": "Glazed" }, {
"id": "5005", "type": "Sugar" }, {
"id": "5007", "type": "Powdered
Sugar" }, {
"id": "5006", "type": "Chocolate with
Sprinkles" }, {
"id": "5003", "type": "Chocolate" }, {
"id": "5004", "type": "Maple" } ] }, { "id":
"0002", "type":
"donut", "name":
"Raised", "ppu":
0.55, "batters": { "batter": [ {
"id": "1001", "type": "Regular" } ] }, "topping": [ {
"id": "5001", "type": "None" }, {
"id": "5002", "type": "Glazed" }, {
"id": "5005", "type": "Sugar" }, {
"id": "5003", "type": "Chocolate" }, {
"id": "5004", "type": "Maple" } ] }, { "id":
"0003", "type":
"donut", "name":
"Old Fashioned", "ppu":
0.55, "batters": { "batter": [ {
"id": "1001", "type": "Regular" }, {
"id": "1002", "type": "Chocolate" } ] }, "topping": [ {
"id": "5001", "type": "None" }, {
"id": "5002", "type": "Glazed" }, {
"id": "5003", "type": "Chocolate" }, {
"id": "5004", "type": "Maple" } ] } ] |
Target DDL: CREATE TABLE "DEMO"."JSON_TABLE" ( "FILE_NAME" VARCHAR2(255 BYTE), "LOAD_DATE"
VARCHAR2(255 BYTE), "ID"
NUMBER(10,0), "NAME"
VARCHAR2(255 BYTE), "PPU"
NUMBER(10,2), "TYPE"
VARCHAR2(255 BYTE), "SEQ_NUM"
NUMBER(10,0), "BATTER_ID"
NUMBER(10,0), "BATTER_TYPE"
VARCHAR2(255 BYTE), "TOPPING_ID"
NUMBER(10,0), "SEQ_TOPPING"
NUMBER(10,0), "TOPPING_TYPE"
VARCHAR2(255 BYTE) ) |
begin
EXECUTE IMMEDIATE 'truncate table emp_hierarchy';
EXECUTE
IMMEDIATE 'truncate table emp_hi';
FOR
i IN (
SELECT
employee_id
FROM
hr.employees
ORDER BY
employee_id
)
loop
EXECUTE IMMEDIATE 'drop table employees';
EXECUTE IMMEDIATE 'create table employees
as select * from hr.employees where employee_id=' || i.employee_id;
EXECUTE IMMEDIATE 'truncate table
emp_hi';
INSERT INTO emp_hi
WITH cte (
employee_id,
first_name,
manager_id,
pos
) AS (
SELECT
employee_id,
first_name,
manager_id,
1 pos
FROM
employees
UNION ALL
SELECT
cte.employee_id,
mgr.first_name,
mgr.manager_id,
cte.pos + 1 pos
FROM
hr.employees mgr,
cte
WHERE
mgr.employee_id =
cte.manager_id
)
SELECT
employee_id,
first_name,
5 - pos pos
FROM
cte;
COMMIT;
INSERT INTO emp_hierarchy
SELECT
employee_id,
mgr_level4,
coalesce(mgr_level3, mgr_level4)
mgr_level3,
coalesce(mgr_level2, mgr_level3,
mgr_level4) mgr_level2,
coalesce(mgr_level1, mgr_level2,
mgr_level3, mgr_level4) mgr_level1
FROM
emp_hi PIVOT (
MAX ( first_name )
FOR pos
IN ( 4 mgr_level4, 3
mgr_level3, 2 mgr_level2, 1 mgr_level1 )
);
commit;
end loop;
END;
|