Documente Academic
Documente Profesional
Documente Cultură
Extraction, Transformation,
and Loading (ETL)
Transformation
Objectives
After completing this lesson, you should be able to do
the following:
Explain transformation using SQL
6-2
Data Transformation
6-3
NEW_SALES_STEP1
Flat files
Validate customer
keys (look up in
customer
dimension table).
NEW_SALES_STEP3
6-4
Convert source
product keys
to warehouse
product keys.
NEW_SALES_STEP2
SALES
External table
Validate customer
keys (look up in
customer
dimension table).
Flat files
Convert source
product keys
to warehouse
product keys.
6-5
SALES
Transformation Mechanisms
You have the following choices for transforming data
inside the database:
SQL
PL/SQL
Table functions
6-6
6-7
6-10
6-11
6-12
6-13
Unconditional INSERT
Pivoting INSERT
Conditional ALL INSERT
Conditional FIRST INSERT
INSERT ALL
INTO sales VALUES (product_id, customer_id, today, 3,
promotion_id, quantity_per_day, amount_per_day)
INTO costs VALUES (product_id, today, promotion_id, 3,
product_cost, product_price)
SELECT TRUNC(s.sales_date) AS today, s.product_id,
s.customer_id, s.promotion_id, SUM(s.amount)
AS amount_per_day, SUM(s.quantity) quantity_per_day,
p.prod_min_price*0.8 AS product_cost, p.prod_list_price
AS product_price
FROM sales_activity_direct s, products p
WHERE s.product_id = p.prod_id AND TRUNC(sales_date) =
TRUNC(SYSDATE)
GROUP BY TRUNC(sales_date), s.product_id, s.customer_id,
s.promotion_id, p.prod_min_price*0.8, p.prod_list_price;
6-14
INSERT ALL
WHEN product_id IN (SELECT product_id
FROM
promotional_items) THEN
INTO promotional_sales
VALUES(product_id,list_price)
WHEN order_mode = 'online' THEN
INTO web_orders VALUES(product_id, order_total)
SELECT product_id, list_price, order_total,
order_mode
FROM orders;
6-15
6-16
6-17
6-18
6-19
SELECT *
FROM TABLE(transform(cursor(SELECT *
FROM
order_items_ext)));
INSERT /*+ APPEND, PARALLEL(order_items) */
INTO order_items
SELECT *
FROM TABLE(transform(cursor(SELECT *
FROM
order_items_ext)));
6-21
6-22
6-23
Error-Logging Table
6-25
Data type
Information
ORA_ERR_NUMBER$
varchar2(10)
ORA_ERR_MESG$
varchar2(4000)
ORA_ERR_ROWID$
row ID
ORA_ERR_OPTYP$
varchar2(2)
ORA_ERR_TAG$
varchar2(4000)
6-27
EXECUTE DBMS_ERRLOG.CREATE_ERROR_LOG('bonuses',
'errlog');
6-28
Summary
In this lesson, you should have learned how to:
Explain transformation using SQL
6-29
Practice 6: Overview
This practice covers the following topics:
Loading data using multitable inserts
Loading data using multitable conditional insert
Loading data using MERGE
Logging DML load errors
6-30