etl by sql - jeff kemp on oracle · •oracle forms, reports, sql, pl/sql - 11 years •oracle apex...

87
ETL by SQL AUSOUG Conference Perth 2011 Jeffrey Kemp jeffkemponoracle.com

Upload: others

Post on 05-Aug-2020

13 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: ETL by SQL - Jeff Kemp on Oracle · •Oracle Forms, Reports, SQL, PL/SQL - 11 years •Oracle Apex - 5 years. 2 projects. ... •No triggers Destination Columns •Prefixed with

ETL by SQLAUSOUG Conference Perth 2011

Jeffrey Kemp

jeffkemponoracle.com

Page 2: ETL by SQL - Jeff Kemp on Oracle · •Oracle Forms, Reports, SQL, PL/SQL - 11 years •Oracle Apex - 5 years. 2 projects. ... •No triggers Destination Columns •Prefixed with

About Me

• Oracle Forms, Reports, SQL, PL/SQL - 11 years

• Oracle Apex - 5 years

Page 3: ETL by SQL - Jeff Kemp on Oracle · •Oracle Forms, Reports, SQL, PL/SQL - 11 years •Oracle Apex - 5 years. 2 projects. ... •No triggers Destination Columns •Prefixed with
Page 4: ETL by SQL - Jeff Kemp on Oracle · •Oracle Forms, Reports, SQL, PL/SQL - 11 years •Oracle Apex - 5 years. 2 projects. ... •No triggers Destination Columns •Prefixed with
Page 5: ETL by SQL - Jeff Kemp on Oracle · •Oracle Forms, Reports, SQL, PL/SQL - 11 years •Oracle Apex - 5 years. 2 projects. ... •No triggers Destination Columns •Prefixed with

2 projects

Page 6: ETL by SQL - Jeff Kemp on Oracle · •Oracle Forms, Reports, SQL, PL/SQL - 11 years •Oracle Apex - 5 years. 2 projects. ... •No triggers Destination Columns •Prefixed with

New BondsLegacy Bonds

Page 7: ETL by SQL - Jeff Kemp on Oracle · •Oracle Forms, Reports, SQL, PL/SQL - 11 years •Oracle Apex - 5 years. 2 projects. ... •No triggers Destination Columns •Prefixed with

AssociationsBusiness Names

Page 8: ETL by SQL - Jeff Kemp on Oracle · •Oracle Forms, Reports, SQL, PL/SQL - 11 years •Oracle Apex - 5 years. 2 projects. ... •No triggers Destination Columns •Prefixed with

THEIR REQUIREMENTS:

Migrate all the data.

Page 9: ETL by SQL - Jeff Kemp on Oracle · •Oracle Forms, Reports, SQL, PL/SQL - 11 years •Oracle Apex - 5 years. 2 projects. ... •No triggers Destination Columns •Prefixed with

MY REQUIREMENTS:

1. Get it done; and

Page 10: ETL by SQL - Jeff Kemp on Oracle · •Oracle Forms, Reports, SQL, PL/SQL - 11 years •Oracle Apex - 5 years. 2 projects. ... •No triggers Destination Columns •Prefixed with

MY REQUIREMENTS:

2. Don't get called back.

Page 11: ETL by SQL - Jeff Kemp on Oracle · •Oracle Forms, Reports, SQL, PL/SQL - 11 years •Oracle Apex - 5 years. 2 projects. ... •No triggers Destination Columns •Prefixed with

MY REQUIREMENTS:

1. Never lose track.

Page 12: ETL by SQL - Jeff Kemp on Oracle · •Oracle Forms, Reports, SQL, PL/SQL - 11 years •Oracle Apex - 5 years. 2 projects. ... •No triggers Destination Columns •Prefixed with

MY REQUIREMENTS:

2. Make a time machine.

Page 13: ETL by SQL - Jeff Kemp on Oracle · •Oracle Forms, Reports, SQL, PL/SQL - 11 years •Oracle Apex - 5 years. 2 projects. ... •No triggers Destination Columns •Prefixed with

the Old way

Page 14: ETL by SQL - Jeff Kemp on Oracle · •Oracle Forms, Reports, SQL, PL/SQL - 11 years •Oracle Apex - 5 years. 2 projects. ... •No triggers Destination Columns •Prefixed with

a Better way

E T L

Page 15: ETL by SQL - Jeff Kemp on Oracle · •Oracle Forms, Reports, SQL, PL/SQL - 11 years •Oracle Apex - 5 years. 2 projects. ... •No triggers Destination Columns •Prefixed with

Transform?http://en.wikipedia.org/wiki/Extract,_transform,_load• Selecting only certain columns to load• Translating coded values• Encoding free-form values

(e.g., mapping "Male" to "1" and "Mr" to M)• Deriving a new calculated value• Sorting• Joining data from multiple sources• Aggregation• Generating surrogate-key values• Transposing or pivoting• Splitting a column into multiple columns• Disaggregation of repeating columns into a separate

detail table• Lookup and validate the relevant data from tables or

referential files• Applying any form of simple or complex data

validation

"

"

SQL

SQL

SQL

SQL

SQL

SQL

SQL

SQL

SQL

SQL

SQL

SQL

SQL

Page 16: ETL by SQL - Jeff Kemp on Oracle · •Oracle Forms, Reports, SQL, PL/SQL - 11 years •Oracle Apex - 5 years. 2 projects. ... •No triggers Destination Columns •Prefixed with

a Better way

SPOD

Page 17: ETL by SQL - Jeff Kemp on Oracle · •Oracle Forms, Reports, SQL, PL/SQL - 11 years •Oracle Apex - 5 years. 2 projects. ... •No triggers Destination Columns •Prefixed with

Example

Page 18: ETL by SQL - Jeff Kemp on Oracle · •Oracle Forms, Reports, SQL, PL/SQL - 11 years •Oracle Apex - 5 years. 2 projects. ... •No triggers Destination Columns •Prefixed with

Legacy Model

BOOKS Data Type

ISBN VARCHAR2(13)

TITLE VARCHAR2(100)

COPIES INTEGER

PRICE NUMBER(5,2)

BOOK_ID INTEGER

CODE VARCHAR2(3)

AUTHORS Data Type

ISBN VARCHAR2(13)

NAME VARCHAR2(100)

TAGS Data Type

BOOK_ID INTEGER

TAG VARCHAR2(20)

Page 19: ETL by SQL - Jeff Kemp on Oracle · •Oracle Forms, Reports, SQL, PL/SQL - 11 years •Oracle Apex - 5 years. 2 projects. ... •No triggers Destination Columns •Prefixed with

New Model

BOOKS Data Type

BOOK_ID NUMBER(10)

ISBN VARCHAR2(13)

TITLE VARCHAR2(50)

PUBLISHER VARCHAR2(100)

TAG_LIST VARCHAR2(1000)

AUTHORS Data Type

AUTHOR_ID NUMBER(10)

AUTHOR_NAME VARCHAR2(100)COPIES Data Type

COPY_ID NUMBER(10)

BOOK_ID NUMBER(10)

COST NUMBER(5,2)

OWNER VARCHAR2(30)

BOOK_AUTHORS Data Type

BOOK_ID NUMBER(10)

AUTHOR_ID NUMBER(10)

Page 20: ETL by SQL - Jeff Kemp on Oracle · •Oracle Forms, Reports, SQL, PL/SQL - 11 years •Oracle Apex - 5 years. 2 projects. ... •No triggers Destination Columns •Prefixed with

Data Model Analysis

ConstraintsFrequency Histograms

Stats

Application Code

Business Rules

Domain Knowledge

Page 21: ETL by SQL - Jeff Kemp on Oracle · •Oracle Forms, Reports, SQL, PL/SQL - 11 years •Oracle Apex - 5 years. 2 projects. ... •No triggers Destination Columns •Prefixed with

Map to New from Legacy

DESTINATION (NEW) Data Type

BOOKS

BOOK_ID NUMBER(10)

ISBN VARCHAR2(13)

TITLE VARCHAR2(50)

PUBLISHER VARCHAR2(100)

TAG_LIST VARCHAR2(1000)

Oracle Data Dictionary Views

Page 22: ETL by SQL - Jeff Kemp on Oracle · •Oracle Forms, Reports, SQL, PL/SQL - 11 years •Oracle Apex - 5 years. 2 projects. ... •No triggers Destination Columns •Prefixed with

Map to New from Legacy

DESTINATION (NEW) Data Type SOURCE (LEGACY) Data Type

BOOKS BOOKS

BOOK_ID NUMBER(10)

ISBN VARCHAR2(13)

TITLE VARCHAR2(50)

PUBLISHER VARCHAR2(100)

TAG_LIST VARCHAR2(1000)

Page 23: ETL by SQL - Jeff Kemp on Oracle · •Oracle Forms, Reports, SQL, PL/SQL - 11 years •Oracle Apex - 5 years. 2 projects. ... •No triggers Destination Columns •Prefixed with

Map to New from Legacy

DESTINATION (NEW) Data Type SOURCE (LEGACY) Data Type

BOOKS BOOKS

BOOK_ID NUMBER(10) BOOKS.BOOK_ID INTEGER

ISBN VARCHAR2(13) BOOKS.ISBN VARCHAR2(10)

TITLE VARCHAR2(50) BOOKS.TITLE VARCHAR2(100)

PUBLISHER VARCHAR2(100)

TAG_LIST VARCHAR2(1000)

Page 24: ETL by SQL - Jeff Kemp on Oracle · •Oracle Forms, Reports, SQL, PL/SQL - 11 years •Oracle Apex - 5 years. 2 projects. ... •No triggers Destination Columns •Prefixed with

Map to New from Legacy

DESTINATION (NEW) Data Type SOURCE (LEGACY) Data Type

BOOKS BOOKS

BOOK_ID NUMBER(10) BOOKS.BOOK_ID INTEGER

ISBN VARCHAR2(13) BOOKS.ISBN VARCHAR2(10)

TITLE VARCHAR2(50) BOOKS.TITLE VARCHAR2(100)

PUBLISHER VARCHAR2(100) (null)

TAG_LIST VARCHAR2(1000)

Page 25: ETL by SQL - Jeff Kemp on Oracle · •Oracle Forms, Reports, SQL, PL/SQL - 11 years •Oracle Apex - 5 years. 2 projects. ... •No triggers Destination Columns •Prefixed with

Map to New from Legacy

DESTINATION (NEW) Data Type SOURCE (LEGACY) Data Type

BOOKS BOOKS, TAGS

BOOK_ID NUMBER(10) BOOKS.BOOK_ID INTEGER

ISBN VARCHAR2(13) BOOKS.ISBN VARCHAR2(10)

TITLE VARCHAR2(50) BOOKS.TITLE VARCHAR2(100)

PUBLISHER VARCHAR2(100) (null)

TAG_LIST VARCHAR2(1000) TAGS.TAG (aggregate) VARCHAR2(20)

Page 26: ETL by SQL - Jeff Kemp on Oracle · •Oracle Forms, Reports, SQL, PL/SQL - 11 years •Oracle Apex - 5 years. 2 projects. ... •No triggers Destination Columns •Prefixed with

Map to New from Legacy

DESTINATION (NEW) Data Type SOURCE (LEGACY) Data Type

BOOKS BOOKS, TAGS

BOOK_ID NUMBER(10) BOOKS.BOOK_ID or new sequence

INTEGER

ISBN VARCHAR2(13) BOOKS.ISBN VARCHAR2(10)

TITLE VARCHAR2(50) BOOKS.TITLE(clean & truncate)

VARCHAR2(100)

PUBLISHER VARCHAR2(100) (null)

TAG_LIST VARCHAR2(1000) TAGS.TAG (aggregate) VARCHAR2(20)

Page 27: ETL by SQL - Jeff Kemp on Oracle · •Oracle Forms, Reports, SQL, PL/SQL - 11 years •Oracle Apex - 5 years. 2 projects. ... •No triggers Destination Columns •Prefixed with

Map to New from Legacy

DESTINATION (NEW) Data Type SOURCE (LEGACY) Data Type

AUTHORS AUTHORS

AUTHOR_ID NUMBER(10) (new sequence)

AUTHOR_NAME VARCHAR2(100) AUTHORS.NAME VARCHAR2(100)

BOOK_AUTHORS AUTHORS

BOOK_ID NUMBER(10) BOOKS.BOOK_ID INTEGER

AUTHOR_ID NUMBER(10) (ref AUTHORS)

Page 28: ETL by SQL - Jeff Kemp on Oracle · •Oracle Forms, Reports, SQL, PL/SQL - 11 years •Oracle Apex - 5 years. 2 projects. ... •No triggers Destination Columns •Prefixed with

Map to New from Legacy

DESTINATION (NEW) Data Type SOURCE (LEGACY) Data Type

COPIES BOOKS.COPIES (1 row for each copy)

COPY_ID NUMBER(10) (new sequence)

BOOK_ID NUMBER(10) BOOKS.BOOK_ID INTEGER

COST NUMBER(5,2) BOOKS.PRICE NUMBER(5,2)

OWNER VARCHAR2(30) 'Jeff'

Page 29: ETL by SQL - Jeff Kemp on Oracle · •Oracle Forms, Reports, SQL, PL/SQL - 11 years •Oracle Apex - 5 years. 2 projects. ... •No triggers Destination Columns •Prefixed with

Map from Legacy back to NewSOURCE (LEGACY) Data Type DESTINATION (NEW) Data Type

BOOKS

ISBN VARCHAR2(13)

TITLE VARCHAR2(100)

COPIES INTEGER

PRICE NUMBER(5,2)

BOOK_ID INTEGER

CODE VARCHAR2(3)

AUTHORS

ISBN VARCHAR2(13)

NAME VARCHAR2(100)

TAGS

BOOK_ID INTEGER

TAG VARCHAR2(20)

Page 30: ETL by SQL - Jeff Kemp on Oracle · •Oracle Forms, Reports, SQL, PL/SQL - 11 years •Oracle Apex - 5 years. 2 projects. ... •No triggers Destination Columns •Prefixed with

Map from Legacy back to NewSOURCE (LEGACY) Data Type DESTINATION (NEW) Data Type

BOOKS

ISBN VARCHAR2(13) BOOKS.ISBN VARCHAR2(13)

TITLE VARCHAR2(100) BOOKS.TITLE VARCHAR2(50)

COPIES INTEGER COPIES (multiple records)

PRICE NUMBER(5,2) COPIES.COST NUMBER(5,2)

BOOK_ID INTEGER BOOKS.BOOK_ID ? NUMBER(10)

CODE VARCHAR2(3) ?

AUTHORS

ISBN VARCHAR2(13) ref to BOOKS

NAME VARCHAR2(100) AUTHORS.AUTHOR_NAME VARCHAR2(100)

TAGS

BOOK_ID INTEGER ref to BOOKS

TAG VARCHAR2(20) BOOKS.TAG_LIST VARCHAR2(1000)

Page 31: ETL by SQL - Jeff Kemp on Oracle · •Oracle Forms, Reports, SQL, PL/SQL - 11 years •Oracle Apex - 5 years. 2 projects. ... •No triggers Destination Columns •Prefixed with

ETL Architecture

LEGACY MIGRATE <new>READ WRITE

other

CSVOracle

Page 32: ETL by SQL - Jeff Kemp on Oracle · •Oracle Forms, Reports, SQL, PL/SQL - 11 years •Oracle Apex - 5 years. 2 projects. ... •No triggers Destination Columns •Prefixed with

the Process

E

• snapshot of source data into LEGACY schema

T

• INSERT/ UPDATE MIGRATE tables from LEGACY

L

• INSERT/ UPDATE NEW tables from MIGRATE

Page 33: ETL by SQL - Jeff Kemp on Oracle · •Oracle Forms, Reports, SQL, PL/SQL - 11 years •Oracle Apex - 5 years. 2 projects. ... •No triggers Destination Columns •Prefixed with

Intermediate tables

•Same names

•Same (or similar) data types

•No constraints

•No triggers

Destination Columns

•Prefixed with "OLD_"

• Indexed

•Unique constraintSource IDs

•Default NULL

•Set to 'Y' to mark rows that have been deleted in SourceDeleted flag

Page 34: ETL by SQL - Jeff Kemp on Oracle · •Oracle Forms, Reports, SQL, PL/SQL - 11 years •Oracle Apex - 5 years. 2 projects. ... •No triggers Destination Columns •Prefixed with

Intermediate table: BOOKS

CREATE TABLE BOOKS ASSELECT * FROM NEW.BOOKS WHERE 1=0;

ALTER TABLE BOOKS ADD(old_isbn VARCHAR2(20) NOT NULL,CONSTRAINT books_pk

PRIMARY KEY (old_isbn));

ALTER TABLE BOOKS ADD (deleted CHAR(1));

Page 35: ETL by SQL - Jeff Kemp on Oracle · •Oracle Forms, Reports, SQL, PL/SQL - 11 years •Oracle Apex - 5 years. 2 projects. ... •No triggers Destination Columns •Prefixed with
Page 36: ETL by SQL - Jeff Kemp on Oracle · •Oracle Forms, Reports, SQL, PL/SQL - 11 years •Oracle Apex - 5 years. 2 projects. ... •No triggers Destination Columns •Prefixed with

Transformer

MERGE INTO MIGRATE.BOOKSAS d

Page 37: ETL by SQL - Jeff Kemp on Oracle · •Oracle Forms, Reports, SQL, PL/SQL - 11 years •Oracle Apex - 5 years. 2 projects. ... •No triggers Destination Columns •Prefixed with

Transformer

MERGE INTO MIGRATE.BOOKSAS d

USING (transformation query)AS s

Page 38: ETL by SQL - Jeff Kemp on Oracle · •Oracle Forms, Reports, SQL, PL/SQL - 11 years •Oracle Apex - 5 years. 2 projects. ... •No triggers Destination Columns •Prefixed with

Transformer

MERGE INTO MIGRATE.BOOKSAS d

USING (transformation query)AS s

ON (d.old_isbn = s.old_isbn)

Page 39: ETL by SQL - Jeff Kemp on Oracle · •Oracle Forms, Reports, SQL, PL/SQL - 11 years •Oracle Apex - 5 years. 2 projects. ... •No triggers Destination Columns •Prefixed with

Transformer

MERGE INTO MIGRATE.BOOKSAS d

USING (transformation query)AS s

ON (d.old_isbn = s.old_isbn)WHEN MATCHED

THEN UPDATE ...WHEN NOT MATCHED

THEN INSERT ...

Page 40: ETL by SQL - Jeff Kemp on Oracle · •Oracle Forms, Reports, SQL, PL/SQL - 11 years •Oracle Apex - 5 years. 2 projects. ... •No triggers Destination Columns •Prefixed with

transformation query

Page 41: ETL by SQL - Jeff Kemp on Oracle · •Oracle Forms, Reports, SQL, PL/SQL - 11 years •Oracle Apex - 5 years. 2 projects. ... •No triggers Destination Columns •Prefixed with

Map to New from Legacy

DESTINATION (NEW) Data Type SOURCE (LEGACY) Data Type

BOOKS BOOKS, TAGS

BOOK_ID NUMBER(10) new sequence

ISBN VARCHAR2(13) BOOKS.ISBN VARCHAR2(10)

TITLE VARCHAR2(50) BOOKS.TITLE(clean & truncate)

VARCHAR2(100)

PUBLISHER VARCHAR2(100) (null)

TAG_LIST VARCHAR2(1000) TAGS.TAG (aggregate) VARCHAR2(20)

Page 42: ETL by SQL - Jeff Kemp on Oracle · •Oracle Forms, Reports, SQL, PL/SQL - 11 years •Oracle Apex - 5 years. 2 projects. ... •No triggers Destination Columns •Prefixed with

transformation query

SELECT null AS OLD_ISBN

,null AS ISBN

,null AS TITLE

,null AS PUBLISHER

,null AS TAG_LIST

FROM LEGACY.BOOKS b;

Page 43: ETL by SQL - Jeff Kemp on Oracle · •Oracle Forms, Reports, SQL, PL/SQL - 11 years •Oracle Apex - 5 years. 2 projects. ... •No triggers Destination Columns •Prefixed with

transformation query

SELECT b.isbn AS OLD_ISBN

,b.isbn AS ISBN

,SUBSTR(b.title,1,200) AS TITLE

,null AS PUBLISHER

,null AS TAG_LIST

FROM LEGACY.BOOKS b;

Page 44: ETL by SQL - Jeff Kemp on Oracle · •Oracle Forms, Reports, SQL, PL/SQL - 11 years •Oracle Apex - 5 years. 2 projects. ... •No triggers Destination Columns •Prefixed with

transformation query

SELECT DISTINCT

b.isbn AS OLD_ISBN

,b.isbn AS ISBN

,SUBSTR(b.title,1,200) AS TITLE

,null AS PUBLISHER

,LISTAGG(t.tag,':')

WITHIN GROUP (ORDER BY t.tag)

PARTITION BY (t.book_id) AS TAG_LIST

FROM LEGACY.BOOKS b

,LEGACY.TAGS t

WHERE b.book_id = t.book_id;

Page 45: ETL by SQL - Jeff Kemp on Oracle · •Oracle Forms, Reports, SQL, PL/SQL - 11 years •Oracle Apex - 5 years. 2 projects. ... •No triggers Destination Columns •Prefixed with

TransformedMERGE INTO MIGRATE.BOOKS AS dUSING (

...transformation query goes here...

) AS sON (d.old_isbn = s.old_isbn)WHEN MATCHED

THEN UPDATE SET isbn = s.isbn,title = s.title,publisher = s.publisher,tag_list = s.tag_list,deleted = NULL

WHEN NOT MATCHEDTHEN INSERT (old_isbn, book_id

,isbn, title, publisher, tag_list)VALUES (s.old_isbn, NEW.books_seq.NEXTVAL

,s.isbn, s.title, s.publisher, s.tag_list);

Page 46: ETL by SQL - Jeff Kemp on Oracle · •Oracle Forms, Reports, SQL, PL/SQL - 11 years •Oracle Apex - 5 years. 2 projects. ... •No triggers Destination Columns •Prefixed with

TransformedMERGE INTO MIGRATE.BOOKS AS dUSING (

SELECT DISTINCTb.isbn AS OLD_ISBN

,b.isbn AS ISBN,SUBSTR(b.title,1,200) AS TITLE,null AS PUBLISHER,LISTAGG(t.tag,':')WITHIN GROUP (ORDER BY t.tag)PARTITION BY (t.book_id) AS TAG_LIST

FROM LEGACY.BOOKS b,LEGACY.TAGS t

WHERE b.book_id = t.book_id

) AS sON (d.old_isbn = s.old_isbn)WHEN MATCHED

THEN UPDATE SET isbn = s.isbn,title = s.title,publisher = s.publisher,tag_list = s.tag_list,deleted = NULL

WHEN NOT MATCHEDTHEN INSERT (old_isbn, book_id

,isbn, title, publisher, tag_list)VALUES (s.old_isbn, NEW.books_seq.NEXTVAL

,s.isbn, s.title, s.publisher, s.tag_list);

SPOD

Page 47: ETL by SQL - Jeff Kemp on Oracle · •Oracle Forms, Reports, SQL, PL/SQL - 11 years •Oracle Apex - 5 years. 2 projects. ... •No triggers Destination Columns •Prefixed with

Set Deleted flag

UPDATE MIGRATE.BOOKS bSET b.deleted = 'Y'WHERE b.deleted IS NULLAND NOT EXISTS (SELECT nullFROM LEGACY.BOOKS aWHERE a.isbn = b.old_isbn);

Page 48: ETL by SQL - Jeff Kemp on Oracle · •Oracle Forms, Reports, SQL, PL/SQL - 11 years •Oracle Apex - 5 years. 2 projects. ... •No triggers Destination Columns •Prefixed with

LOAD

Page 49: ETL by SQL - Jeff Kemp on Oracle · •Oracle Forms, Reports, SQL, PL/SQL - 11 years •Oracle Apex - 5 years. 2 projects. ... •No triggers Destination Columns •Prefixed with

Loader

MERGE INTO NEW.booksAS d

Page 50: ETL by SQL - Jeff Kemp on Oracle · •Oracle Forms, Reports, SQL, PL/SQL - 11 years •Oracle Apex - 5 years. 2 projects. ... •No triggers Destination Columns •Prefixed with

Loader

MERGE INTO NEW.booksAS d

USING (SELECT *FROM MIGRATE.books)

AS sON (d.book_id = s.book_id)WHEN MATCHED

THEN UPDATE ...

WHEN NOT MATCHEDTHEN INSERT ...

Page 51: ETL by SQL - Jeff Kemp on Oracle · •Oracle Forms, Reports, SQL, PL/SQL - 11 years •Oracle Apex - 5 years. 2 projects. ... •No triggers Destination Columns •Prefixed with

Loader

MERGE INTO NEW.booksAS d

USING (SELECT *FROM MIGRATE.books)

AS sON (d.book_id = s.book_id)WHEN MATCHED

THEN UPDATE ...DELETE WHERE deleted IS NOT NULLWHEN NOT MATCHED

THEN INSERT ...

Page 52: ETL by SQL - Jeff Kemp on Oracle · •Oracle Forms, Reports, SQL, PL/SQL - 11 years •Oracle Apex - 5 years. 2 projects. ... •No triggers Destination Columns •Prefixed with

Error Log

DBMS_ERRLOG.CREATE_ERROR_LOG(dml_table_name => 'NEW.BOOKS',err_log_table_name => 'ERR$BOOKS',err_log_table_owner => 'MIGRATE');

Page 53: ETL by SQL - Jeff Kemp on Oracle · •Oracle Forms, Reports, SQL, PL/SQL - 11 years •Oracle Apex - 5 years. 2 projects. ... •No triggers Destination Columns •Prefixed with

Loader + Error Log

MERGE INTO NEW.booksAS d

USING (SELECT *FROM MIGRATE.books)

AS sON (d.book_id = s.book_id)WHEN MATCHED

THEN UPDATE ...DELETE WHERE deleted IS NOT NULLWHEN NOT MATCHED

THEN INSERT ...

Page 54: ETL by SQL - Jeff Kemp on Oracle · •Oracle Forms, Reports, SQL, PL/SQL - 11 years •Oracle Apex - 5 years. 2 projects. ... •No triggers Destination Columns •Prefixed with

Loader + Error Log

MERGE INTO NEW.booksAS d

USING (SELECT *FROM MIGRATE.books)

AS sON (d.book_id = s.book_id)WHEN MATCHED

THEN UPDATE ...DELETE WHERE deleted IS NOT NULLWHEN NOT MATCHED

THEN INSERT ...LOG ERRORS INTO MIGRATE.ERR$BOOKSREJECT LIMIT UNLIMITED;

Page 55: ETL by SQL - Jeff Kemp on Oracle · •Oracle Forms, Reports, SQL, PL/SQL - 11 years •Oracle Apex - 5 years. 2 projects. ... •No triggers Destination Columns •Prefixed with

Report Load Error Stats

SELECT ora_err_mesg$, COUNT(*)FROM ERR$BOOKSGROUP BY ora_err_mesg$ORDER BY 2 DESC;

ORA_ERR_MESG$ COUNT(*)----------------------------------------------- --------ORA-00001: unique constraint violated(BOOKS.BOOK_PK) 7 ORA-12899: value too large for column "NEW"."BOOKS"."TITLE" (actual: 52, maximum: 50) 1

Page 56: ETL by SQL - Jeff Kemp on Oracle · •Oracle Forms, Reports, SQL, PL/SQL - 11 years •Oracle Apex - 5 years. 2 projects. ... •No triggers Destination Columns •Prefixed with

Oracle Features UsedO

racl

e 9

.0.1

• MERGE

Ora

cle

10

.1

• MERGE+DELETE

Ora

cle

10

.2

• MERGE+DELETE+LOG ERRORS

Page 57: ETL by SQL - Jeff Kemp on Oracle · •Oracle Forms, Reports, SQL, PL/SQL - 11 years •Oracle Apex - 5 years. 2 projects. ... •No triggers Destination Columns •Prefixed with

DEMO

Page 58: ETL by SQL - Jeff Kemp on Oracle · •Oracle Forms, Reports, SQL, PL/SQL - 11 years •Oracle Apex - 5 years. 2 projects. ... •No triggers Destination Columns •Prefixed with
Page 59: ETL by SQL - Jeff Kemp on Oracle · •Oracle Forms, Reports, SQL, PL/SQL - 11 years •Oracle Apex - 5 years. 2 projects. ... •No triggers Destination Columns •Prefixed with
Page 60: ETL by SQL - Jeff Kemp on Oracle · •Oracle Forms, Reports, SQL, PL/SQL - 11 years •Oracle Apex - 5 years. 2 projects. ... •No triggers Destination Columns •Prefixed with
Page 61: ETL by SQL - Jeff Kemp on Oracle · •Oracle Forms, Reports, SQL, PL/SQL - 11 years •Oracle Apex - 5 years. 2 projects. ... •No triggers Destination Columns •Prefixed with
Page 62: ETL by SQL - Jeff Kemp on Oracle · •Oracle Forms, Reports, SQL, PL/SQL - 11 years •Oracle Apex - 5 years. 2 projects. ... •No triggers Destination Columns •Prefixed with
Page 63: ETL by SQL - Jeff Kemp on Oracle · •Oracle Forms, Reports, SQL, PL/SQL - 11 years •Oracle Apex - 5 years. 2 projects. ... •No triggers Destination Columns •Prefixed with
Page 64: ETL by SQL - Jeff Kemp on Oracle · •Oracle Forms, Reports, SQL, PL/SQL - 11 years •Oracle Apex - 5 years. 2 projects. ... •No triggers Destination Columns •Prefixed with
Page 65: ETL by SQL - Jeff Kemp on Oracle · •Oracle Forms, Reports, SQL, PL/SQL - 11 years •Oracle Apex - 5 years. 2 projects. ... •No triggers Destination Columns •Prefixed with
Page 66: ETL by SQL - Jeff Kemp on Oracle · •Oracle Forms, Reports, SQL, PL/SQL - 11 years •Oracle Apex - 5 years. 2 projects. ... •No triggers Destination Columns •Prefixed with
Page 67: ETL by SQL - Jeff Kemp on Oracle · •Oracle Forms, Reports, SQL, PL/SQL - 11 years •Oracle Apex - 5 years. 2 projects. ... •No triggers Destination Columns •Prefixed with
Page 68: ETL by SQL - Jeff Kemp on Oracle · •Oracle Forms, Reports, SQL, PL/SQL - 11 years •Oracle Apex - 5 years. 2 projects. ... •No triggers Destination Columns •Prefixed with
Page 69: ETL by SQL - Jeff Kemp on Oracle · •Oracle Forms, Reports, SQL, PL/SQL - 11 years •Oracle Apex - 5 years. 2 projects. ... •No triggers Destination Columns •Prefixed with
Page 70: ETL by SQL - Jeff Kemp on Oracle · •Oracle Forms, Reports, SQL, PL/SQL - 11 years •Oracle Apex - 5 years. 2 projects. ... •No triggers Destination Columns •Prefixed with
Page 71: ETL by SQL - Jeff Kemp on Oracle · •Oracle Forms, Reports, SQL, PL/SQL - 11 years •Oracle Apex - 5 years. 2 projects. ... •No triggers Destination Columns •Prefixed with
Page 72: ETL by SQL - Jeff Kemp on Oracle · •Oracle Forms, Reports, SQL, PL/SQL - 11 years •Oracle Apex - 5 years. 2 projects. ... •No triggers Destination Columns •Prefixed with
Page 73: ETL by SQL - Jeff Kemp on Oracle · •Oracle Forms, Reports, SQL, PL/SQL - 11 years •Oracle Apex - 5 years. 2 projects. ... •No triggers Destination Columns •Prefixed with
Page 74: ETL by SQL - Jeff Kemp on Oracle · •Oracle Forms, Reports, SQL, PL/SQL - 11 years •Oracle Apex - 5 years. 2 projects. ... •No triggers Destination Columns •Prefixed with
Page 75: ETL by SQL - Jeff Kemp on Oracle · •Oracle Forms, Reports, SQL, PL/SQL - 11 years •Oracle Apex - 5 years. 2 projects. ... •No triggers Destination Columns •Prefixed with
Page 76: ETL by SQL - Jeff Kemp on Oracle · •Oracle Forms, Reports, SQL, PL/SQL - 11 years •Oracle Apex - 5 years. 2 projects. ... •No triggers Destination Columns •Prefixed with
Page 77: ETL by SQL - Jeff Kemp on Oracle · •Oracle Forms, Reports, SQL, PL/SQL - 11 years •Oracle Apex - 5 years. 2 projects. ... •No triggers Destination Columns •Prefixed with
Page 78: ETL by SQL - Jeff Kemp on Oracle · •Oracle Forms, Reports, SQL, PL/SQL - 11 years •Oracle Apex - 5 years. 2 projects. ... •No triggers Destination Columns •Prefixed with
Page 79: ETL by SQL - Jeff Kemp on Oracle · •Oracle Forms, Reports, SQL, PL/SQL - 11 years •Oracle Apex - 5 years. 2 projects. ... •No triggers Destination Columns •Prefixed with
Page 80: ETL by SQL - Jeff Kemp on Oracle · •Oracle Forms, Reports, SQL, PL/SQL - 11 years •Oracle Apex - 5 years. 2 projects. ... •No triggers Destination Columns •Prefixed with
Page 81: ETL by SQL - Jeff Kemp on Oracle · •Oracle Forms, Reports, SQL, PL/SQL - 11 years •Oracle Apex - 5 years. 2 projects. ... •No triggers Destination Columns •Prefixed with

F I X

Page 82: ETL by SQL - Jeff Kemp on Oracle · •Oracle Forms, Reports, SQL, PL/SQL - 11 years •Oracle Apex - 5 years. 2 projects. ... •No triggers Destination Columns •Prefixed with
Page 83: ETL by SQL - Jeff Kemp on Oracle · •Oracle Forms, Reports, SQL, PL/SQL - 11 years •Oracle Apex - 5 years. 2 projects. ... •No triggers Destination Columns •Prefixed with
Page 84: ETL by SQL - Jeff Kemp on Oracle · •Oracle Forms, Reports, SQL, PL/SQL - 11 years •Oracle Apex - 5 years. 2 projects. ... •No triggers Destination Columns •Prefixed with
Page 85: ETL by SQL - Jeff Kemp on Oracle · •Oracle Forms, Reports, SQL, PL/SQL - 11 years •Oracle Apex - 5 years. 2 projects. ... •No triggers Destination Columns •Prefixed with

Image Creditshttp://www.columbia.edu/cu/computinghistory/cards.html

http://www.emfnews.org/articles/new-research-shows-cell-phones-are-dangerous-part-1/

http://www.howtobeatpanic.com/end-panic-attacks

http://blogs.crikey.com.au/planetalking/2010/01/17/body-scans-and-the-schiphol-soft-sell/

Page 86: ETL by SQL - Jeff Kemp on Oracle · •Oracle Forms, Reports, SQL, PL/SQL - 11 years •Oracle Apex - 5 years. 2 projects. ... •No triggers Destination Columns •Prefixed with

Image Creditshttp://animatedclipart.bestblogsonline.net/transformers-

clipart/

http://www.jonco48.com/blog/wide_20load.jpg

http://www.tapesonline.com.au/media/uploads/image/categories/cat-gaffa.JPG

Page 87: ETL by SQL - Jeff Kemp on Oracle · •Oracle Forms, Reports, SQL, PL/SQL - 11 years •Oracle Apex - 5 years. 2 projects. ... •No triggers Destination Columns •Prefixed with

jeffkemponoracle.com