SlideShare uma empresa Scribd logo
1 de 18
Baixar para ler offline
Oracle10g External Files
                An introduction to what is
                External Tables?




3/4/2010        For a Better Future          1
Introduction
              To have a better understanding of
               how External Table working in
               database.
              By Kai Liu, Sr. Oracle Developer
               Kaitech, Inc.




3/4/2010             For a Better Future           2
Topics of Discussion
              History of External File
               usage?
              Reading External Tables?
              Writing External Tables?



3/4/2010           For a Better Future    3
History of External
           File usage?
              Previously the main method of getting external data into
               the database
               Usually a disjointed process
               – File is put into a directory
               – Loader is run to load into temporary table
               – Validation is done on loaded rows
              Problems?
               – Data File not found
               – Bad Format – rows not loaded
               – Have to load into character fields then validate to
               avoid bad formats
               – Separate steps mean coordination if first step fails or
               does not load all

3/4/2010                  For a Better Future                          4
Control File
           options (errors=200,direct=true)
           load data
           replace
           into table TEMP_DAILY_ORDER_HEADERS
           WHEN REC_TYPE = ‘OH’
           (
           CUST_ID POSITION(001:008) INTEGER EXTERNAL,
           ORDER_ID POSITION(009:016) INTEGER EXTERNAL,
           ORDER_DATE POSITION(017:024) DATE FORMAT ‘YYYYMMDD’,
           NUM_DETAILS POSITION(025:030) INTEGER EXTERNAL,
           REC_TYPE POSITION(079:080) CHAR)
           into table TEMP_DAILY_ORDER_DETAILS
           WHEN REC_TYPE = ‘OD’
           (
           CUST_ID POSITION(001:008) INTEGER EXTERNAL,
           ORDER_ID POSITION(009:016) INTEGER EXTERNAL,
           LINE_NUM POSITION(017:020) INTEGER EXTERNAL,
           PRODUCT_ID POSITION(021:028) CHAR,
           QUANTITY POSITION(029:033) INTEGER EXTERNAL,
           PRICE POSITION(034:041) DECIMAL EXTERNAL,
           AMOUNT POSITION(042:050) DECIMAL EXTERNAL,
           DISCOUNT POSITION(051:057) DECIMAL EXTERNAL,
           NET_AMOUNT POSITION(058:066) DECIMAL EXTERNAL,
           REC_TYPE POSITION(079:080) CHAR)




3/4/2010                       For a Better Future                5
External Table
Reading External Tables?
           Started with Oracle 9i
           • External Files referenced directly from the
              database, as if they were tables
           • Uses ORACLE_LOADER driver
           • Define the file Directories
           • Tables are created with basic file format
           • SELECT used as if file is another table
           • Cannot INSERT, UPDATE or DELETE
           Let’s Demo



3/4/2010             For a Better Future               7
Define Directory
             Create directory where external data files are located
              – files must be in this area
           create directory external_dir as 'c:dataoracleextapp';
           create directory external_bad_dir as
              'c:dataoracleextapp';

           Example in Unix:

           DROP DIRECTORY KMSDATA;

           CREATE OR REPLACE DIRECTORY
            KMSDATA AS '/home/oracle/data';


3/4/2010                For a Better Future                            8
Create the Table Definitions
           Create table TEMP_PUBLICITY_NAME
           (
            ACCT_NBR VARCHAR2(8),
            PUBLICITY_NAME1 VARCHAR2(30),
            PUBLICITY_NAME2 VARCHAR2(30)
           )
           ORGANIZATION EXTERNAL
           (TYPE ORACLE_LOADER
            DEFAULT DIRECTORY dmsdata
            ACCESS PARAMETERS
            (
             RECORDS DELIMITED BY newline
             BADFILE 'publname.bad'
             DISCARDFILE 'publname.dis'
             LOGFILE 'publname.log'
             FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '~'
            (ACCT_NBR CHAR,
             PUBLICITY_NAME1 CHAR,
             PUBLICITY_NAME2 CHAR)
             )
            LOCATION ('PUBLNAME.txt')
            )
            REJECT LIMIT UNLIMITED;
           /


3/4/2010                   For a Better Future                     9
Sample Data File
           ~00002136~,~JANE DOE~,~AND PAPER INCORPORATED~
           ~00017012~,~JOHN AND MARY~,~~
           ~00017013~,~JOHN AND MARY~,~~
           ~00043376~,~MRS MILLS~,~DO NOT ASK FOR PLEDGE-COVERED~
           ~00043833~,~MRS NANCY~,~DO NOT ASK FOR PLEDGE-COVERED~
           ~00051155~,~MRS JAMES~,~DO NOT ASK FOR PLEDGE-COVERED~
           ~00051812~,~MRS WENDY~,~~
           ~00057145~,~MRS CHARLES~,~DO NOT ASK FOR PLEDGE-COVERED~
           ~00081234~,~HARRY~,~(MR STUART L PINKERT)~
           ~06724967~,~MRS CAROL ~,~DO NOT SOLICIT EVER~
           ~14660280~,~BRADEY FAMILY~,~(MR & MRS SMITH)~




3/4/2010                 For a Better Future                          10
Access the table
           Access the table with SQL
           SQL> select * from temp_publicity_name;

           ACCT_NBR PUBLICITY_NAME1                                  PUBLICITY_NAME2
           -------- ------------------------------ ------------------------------
           00002136 JANE DOE AND PAPER INCORPORATED
           00017012 JOHN & MARY
           00017012 JOHN & MARY
           00043376 MRS MILLS                                    DO NOT ASK FOR
           00043833 MRS NANCY                                    DO NOT ASK FOR
           00051155 MRS JAMES                                    DO NOT ASK FOR
           00051812 MRS WENDY
           00057145 MRS CHARLES                                  DO NOT ASK FOR
           00081234 HARRY                                       (MR STUART)
           06724967 MRS CAROL                                    DO NOT EVER
           14660280 BRADY FAMILY                              (MR & MRS SMITH)

           You join good table with these Internal Table.




3/4/2010                          For a Better Future                                  11
Validate the table in PL/SQL
           Invalid format errors automatically go to the
              BAD file
           • How to validate the data?
           1. Access the table and validate records
              that fail
              1. Define bad file as external table with
                 character records
              2. Use PL/SQL to validate the bad records
           2. Define the external table with character
              fields and validate the records
              before loading


3/4/2010             For a Better Future                  12
Check it Out!
           Check if the file exists:
           – File Name is missing from the directory
           – Rename custdata.csv to custdata_mistake.csv
           SQL> select count(*) from temp_publicity_name;
           select count(*) from temp_publicity_name
           *
               ERROR at line 1:
               ORA-29913: error in executing ODCIEXTTABLEOPEN
                callout
               ORA-29400: data cartridge error
               KUP-04040: file PUBLNAME.txt in DMSDATA not found
               ORA-06512: at "SYS.ORACLE_LOADER", line 19–
                Rename file back to PUBLNAME.txt
           SQL> select count(*) from temp_publicity_name;
           COUNT(*)
           ----------
           25
           – Can Use Exception Handling!
3/4/2010                For a Better Future                         13
Writing External Tables
           • New in Oracle 10g
           • Capability to write to an external
              table
           • Oracle-proprietary format
           • Can only be read by Oracle DB
           • Looks like an Export file
           • Can be created, then read
           • Uses ORACLE_DATAPUMP driver
3/4/2010           For a Better Future        14
Write to External Files




3/4/2010             For a Better Future   15
External Tables
           • External tables enable an
              application to import data from files
              and create output files for transfer
              to another Oracle database
           • Easier to follow SQL code than
              Loader control files




3/4/2010            For a Better Future           16
Conclusion
           • External tables in 10g – if you are
              not using them, now is the time to
              start!
           • Loader is still around in 10g, but
              should no longer be used!
           • I still find massive amounts of
              SQL*Loader code in our current
           applications!
           • We should be using this now!

3/4/2010           For a Better Future             17
Thank You
              Q&A?




3/4/2010              For a Better Future   18

Mais conteúdo relacionado

Mais procurados

BCS4L1-Database Management lab.pdf
BCS4L1-Database Management lab.pdfBCS4L1-Database Management lab.pdf
BCS4L1-Database Management lab.pdfKeerthanaP37
 
Does Your IBM i Security Meet the Bar for GDPR?
Does Your IBM i Security Meet the Bar for GDPR?Does Your IBM i Security Meet the Bar for GDPR?
Does Your IBM i Security Meet the Bar for GDPR?Precisely
 
Data Warehouse and Business Intelligence - Recipe 1
Data Warehouse and Business Intelligence - Recipe 1Data Warehouse and Business Intelligence - Recipe 1
Data Warehouse and Business Intelligence - Recipe 1Massimo Cenci
 
Dictionary.coumns is your friend while appending or moving data
Dictionary.coumns is your friend while appending or moving dataDictionary.coumns is your friend while appending or moving data
Dictionary.coumns is your friend while appending or moving dataKiran Venna
 
Sql injection
Sql injectionSql injection
Sql injectionNa Ni
 
SQL Server Learning Drive
SQL Server Learning Drive SQL Server Learning Drive
SQL Server Learning Drive TechandMate
 
SQL Tutorial for BCA-2
SQL Tutorial for BCA-2SQL Tutorial for BCA-2
SQL Tutorial for BCA-2Raj vardhan
 
CIS 336 STUDY Become Exceptional--cis336study.com
CIS 336 STUDY Become Exceptional--cis336study.comCIS 336 STUDY Become Exceptional--cis336study.com
CIS 336 STUDY Become Exceptional--cis336study.comclaric102
 
CIS 336 STUDY Achievement Education--cis336study.com
CIS 336 STUDY Achievement Education--cis336study.comCIS 336 STUDY Achievement Education--cis336study.com
CIS 336 STUDY Achievement Education--cis336study.comclaric153
 

Mais procurados (19)

BCS4L1-Database Management lab.pdf
BCS4L1-Database Management lab.pdfBCS4L1-Database Management lab.pdf
BCS4L1-Database Management lab.pdf
 
MySql slides (ppt)
MySql slides (ppt)MySql slides (ppt)
MySql slides (ppt)
 
How sqlite works
How sqlite worksHow sqlite works
How sqlite works
 
Tables in dd
Tables in ddTables in dd
Tables in dd
 
MySQL Essential Training
MySQL Essential TrainingMySQL Essential Training
MySQL Essential Training
 
Does Your IBM i Security Meet the Bar for GDPR?
Does Your IBM i Security Meet the Bar for GDPR?Does Your IBM i Security Meet the Bar for GDPR?
Does Your IBM i Security Meet the Bar for GDPR?
 
Data Warehouse and Business Intelligence - Recipe 1
Data Warehouse and Business Intelligence - Recipe 1Data Warehouse and Business Intelligence - Recipe 1
Data Warehouse and Business Intelligence - Recipe 1
 
Dictionary.coumns is your friend while appending or moving data
Dictionary.coumns is your friend while appending or moving dataDictionary.coumns is your friend while appending or moving data
Dictionary.coumns is your friend while appending or moving data
 
NOTES ON "FOXPRO"
NOTES ON "FOXPRO" NOTES ON "FOXPRO"
NOTES ON "FOXPRO"
 
SQL
SQLSQL
SQL
 
SQL Basics
SQL BasicsSQL Basics
SQL Basics
 
dbms lab manual
dbms lab manualdbms lab manual
dbms lab manual
 
Sql
SqlSql
Sql
 
Sql injection
Sql injectionSql injection
Sql injection
 
SQL Server Learning Drive
SQL Server Learning Drive SQL Server Learning Drive
SQL Server Learning Drive
 
SQL Tutorial for BCA-2
SQL Tutorial for BCA-2SQL Tutorial for BCA-2
SQL Tutorial for BCA-2
 
CIS 336 STUDY Become Exceptional--cis336study.com
CIS 336 STUDY Become Exceptional--cis336study.comCIS 336 STUDY Become Exceptional--cis336study.com
CIS 336 STUDY Become Exceptional--cis336study.com
 
CIS 336 STUDY Achievement Education--cis336study.com
CIS 336 STUDY Achievement Education--cis336study.comCIS 336 STUDY Achievement Education--cis336study.com
CIS 336 STUDY Achievement Education--cis336study.com
 
Les11 Including Constraints
Les11 Including ConstraintsLes11 Including Constraints
Les11 Including Constraints
 

Destaque

CHX PYTHON INTRO
CHX PYTHON INTROCHX PYTHON INTRO
CHX PYTHON INTROKai Liu
 
What is Listagg?
What is Listagg?What is Listagg?
What is Listagg?Kai Liu
 
PL/SQL11g Question #1
PL/SQL11g Question #1PL/SQL11g Question #1
PL/SQL11g Question #1Kai Liu
 
SQL Tuning Overview
SQL Tuning OverviewSQL Tuning Overview
SQL Tuning OverviewKai Liu
 
Sql Question #3
Sql Question #3Sql Question #3
Sql Question #3Kai Liu
 
Sql Question #5
Sql Question #5Sql Question #5
Sql Question #5Kai Liu
 

Destaque (6)

CHX PYTHON INTRO
CHX PYTHON INTROCHX PYTHON INTRO
CHX PYTHON INTRO
 
What is Listagg?
What is Listagg?What is Listagg?
What is Listagg?
 
PL/SQL11g Question #1
PL/SQL11g Question #1PL/SQL11g Question #1
PL/SQL11g Question #1
 
SQL Tuning Overview
SQL Tuning OverviewSQL Tuning Overview
SQL Tuning Overview
 
Sql Question #3
Sql Question #3Sql Question #3
Sql Question #3
 
Sql Question #5
Sql Question #5Sql Question #5
Sql Question #5
 

Semelhante a Oracle10g External Tables

MySQL Performance Tuning: The Perfect Scalability (OOW2019)
MySQL Performance Tuning: The Perfect Scalability (OOW2019)MySQL Performance Tuning: The Perfect Scalability (OOW2019)
MySQL Performance Tuning: The Perfect Scalability (OOW2019)Mirko Ortensi
 
Changing platforms of Oracle database
Changing platforms of Oracle databaseChanging platforms of Oracle database
Changing platforms of Oracle databasePawanbir Singh
 
Oracle External Tables
Oracle External TablesOracle External Tables
Oracle External Tablesgrogers1124
 
Oracle External Tables
Oracle External TablesOracle External Tables
Oracle External Tablesgrogers1124
 
Practicas oracle10g
Practicas oracle10gPracticas oracle10g
Practicas oracle10grehoscript
 
XMLDB Building Blocks And Best Practices - Oracle Open World 2008 - Marco Gra...
XMLDB Building Blocks And Best Practices - Oracle Open World 2008 - Marco Gra...XMLDB Building Blocks And Best Practices - Oracle Open World 2008 - Marco Gra...
XMLDB Building Blocks And Best Practices - Oracle Open World 2008 - Marco Gra...Marco Gralike
 
Dba 3+ exp qus
Dba 3+ exp qusDba 3+ exp qus
Dba 3+ exp quskrreddy21
 
Oracle Database 12c - New Features for Developers and DBAs
Oracle Database 12c - New Features for Developers and DBAsOracle Database 12c - New Features for Developers and DBAs
Oracle Database 12c - New Features for Developers and DBAsAlex Zaballa
 
Oracle Database 12c - New Features for Developers and DBAs
Oracle Database 12c  - New Features for Developers and DBAsOracle Database 12c  - New Features for Developers and DBAs
Oracle Database 12c - New Features for Developers and DBAsAlex Zaballa
 
Sql introduction
Sql introductionSql introduction
Sql introductionvimal_guru
 
aotc_120805_mwagner
aotc_120805_mwagneraotc_120805_mwagner
aotc_120805_mwagnerMary Wagner
 
How to create a non managed standby database
How to create a non managed  standby databaseHow to create a non managed  standby database
How to create a non managed standby databaseJorge Batista
 
Big Data with MySQL
Big Data with MySQLBig Data with MySQL
Big Data with MySQLIvan Zoratti
 
2008 Collaborate IOUG Presentation
2008 Collaborate IOUG Presentation2008 Collaborate IOUG Presentation
2008 Collaborate IOUG PresentationBiju Thomas
 
database backup and recovery
database backup and recoverydatabase backup and recovery
database backup and recoverysdrhr
 
Oracle RDBMS architecture
Oracle RDBMS architectureOracle RDBMS architecture
Oracle RDBMS architectureMartin Berger
 
Create manula and automaticly database
Create manula and automaticly databaseCreate manula and automaticly database
Create manula and automaticly databaseAnar Godjaev
 
576 oracle-dba-interview-questions
576 oracle-dba-interview-questions576 oracle-dba-interview-questions
576 oracle-dba-interview-questionsNaveen P
 

Semelhante a Oracle10g External Tables (20)

MySQL Performance Tuning: The Perfect Scalability (OOW2019)
MySQL Performance Tuning: The Perfect Scalability (OOW2019)MySQL Performance Tuning: The Perfect Scalability (OOW2019)
MySQL Performance Tuning: The Perfect Scalability (OOW2019)
 
Changing platforms of Oracle database
Changing platforms of Oracle databaseChanging platforms of Oracle database
Changing platforms of Oracle database
 
Oracle External Tables
Oracle External TablesOracle External Tables
Oracle External Tables
 
Oracle External Tables
Oracle External TablesOracle External Tables
Oracle External Tables
 
Practicas oracle10g
Practicas oracle10gPracticas oracle10g
Practicas oracle10g
 
Etl2
Etl2Etl2
Etl2
 
XMLDB Building Blocks And Best Practices - Oracle Open World 2008 - Marco Gra...
XMLDB Building Blocks And Best Practices - Oracle Open World 2008 - Marco Gra...XMLDB Building Blocks And Best Practices - Oracle Open World 2008 - Marco Gra...
XMLDB Building Blocks And Best Practices - Oracle Open World 2008 - Marco Gra...
 
Dba 3+ exp qus
Dba 3+ exp qusDba 3+ exp qus
Dba 3+ exp qus
 
Oracle Database 12c - New Features for Developers and DBAs
Oracle Database 12c - New Features for Developers and DBAsOracle Database 12c - New Features for Developers and DBAs
Oracle Database 12c - New Features for Developers and DBAs
 
Oracle Database 12c - New Features for Developers and DBAs
Oracle Database 12c  - New Features for Developers and DBAsOracle Database 12c  - New Features for Developers and DBAs
Oracle Database 12c - New Features for Developers and DBAs
 
Sql introduction
Sql introductionSql introduction
Sql introduction
 
Database.pptx
Database.pptxDatabase.pptx
Database.pptx
 
aotc_120805_mwagner
aotc_120805_mwagneraotc_120805_mwagner
aotc_120805_mwagner
 
How to create a non managed standby database
How to create a non managed  standby databaseHow to create a non managed  standby database
How to create a non managed standby database
 
Big Data with MySQL
Big Data with MySQLBig Data with MySQL
Big Data with MySQL
 
2008 Collaborate IOUG Presentation
2008 Collaborate IOUG Presentation2008 Collaborate IOUG Presentation
2008 Collaborate IOUG Presentation
 
database backup and recovery
database backup and recoverydatabase backup and recovery
database backup and recovery
 
Oracle RDBMS architecture
Oracle RDBMS architectureOracle RDBMS architecture
Oracle RDBMS architecture
 
Create manula and automaticly database
Create manula and automaticly databaseCreate manula and automaticly database
Create manula and automaticly database
 
576 oracle-dba-interview-questions
576 oracle-dba-interview-questions576 oracle-dba-interview-questions
576 oracle-dba-interview-questions
 

Mais de Kai Liu

QQ and Advance query
QQ and Advance queryQQ and Advance query
QQ and Advance queryKai Liu
 
Schedulers
SchedulersSchedulers
SchedulersKai Liu
 
PL/SQL Example for IF .. ELSIF
PL/SQL Example for IF .. ELSIFPL/SQL Example for IF .. ELSIF
PL/SQL Example for IF .. ELSIFKai Liu
 
Dms 2.0 Direction
Dms 2.0 DirectionDms 2.0 Direction
Dms 2.0 DirectionKai Liu
 
Dms 2.0 Plan Proposal
Dms 2.0 Plan ProposalDms 2.0 Plan Proposal
Dms 2.0 Plan ProposalKai Liu
 
Dms Emailing Reports
Dms Emailing ReportsDms Emailing Reports
Dms Emailing ReportsKai Liu
 
QQ And Advance Query
QQ And Advance QueryQQ And Advance Query
QQ And Advance QueryKai Liu
 
Troubleshooting Batch Reports
Troubleshooting Batch ReportsTroubleshooting Batch Reports
Troubleshooting Batch ReportsKai Liu
 
Dms Reporting Criteria
Dms Reporting CriteriaDms Reporting Criteria
Dms Reporting CriteriaKai Liu
 
Dms Batch Reporting
Dms Batch ReportingDms Batch Reporting
Dms Batch ReportingKai Liu
 
Dms Reporting Overview
Dms Reporting OverviewDms Reporting Overview
Dms Reporting OverviewKai Liu
 
Dms 2 Direction
Dms 2 DirectionDms 2 Direction
Dms 2 DirectionKai Liu
 
Dms Project
Dms ProjectDms Project
Dms ProjectKai Liu
 
Dms Acknowledgements
Dms AcknowledgementsDms Acknowledgements
Dms AcknowledgementsKai Liu
 

Mais de Kai Liu (15)

QQ and Advance query
QQ and Advance queryQQ and Advance query
QQ and Advance query
 
Schedulers
SchedulersSchedulers
Schedulers
 
PL/SQL Example for IF .. ELSIF
PL/SQL Example for IF .. ELSIFPL/SQL Example for IF .. ELSIF
PL/SQL Example for IF .. ELSIF
 
Dms 2.0 Direction
Dms 2.0 DirectionDms 2.0 Direction
Dms 2.0 Direction
 
Dms 2.0 Plan Proposal
Dms 2.0 Plan ProposalDms 2.0 Plan Proposal
Dms 2.0 Plan Proposal
 
Toad
ToadToad
Toad
 
Dms Emailing Reports
Dms Emailing ReportsDms Emailing Reports
Dms Emailing Reports
 
QQ And Advance Query
QQ And Advance QueryQQ And Advance Query
QQ And Advance Query
 
Troubleshooting Batch Reports
Troubleshooting Batch ReportsTroubleshooting Batch Reports
Troubleshooting Batch Reports
 
Dms Reporting Criteria
Dms Reporting CriteriaDms Reporting Criteria
Dms Reporting Criteria
 
Dms Batch Reporting
Dms Batch ReportingDms Batch Reporting
Dms Batch Reporting
 
Dms Reporting Overview
Dms Reporting OverviewDms Reporting Overview
Dms Reporting Overview
 
Dms 2 Direction
Dms 2 DirectionDms 2 Direction
Dms 2 Direction
 
Dms Project
Dms ProjectDms Project
Dms Project
 
Dms Acknowledgements
Dms AcknowledgementsDms Acknowledgements
Dms Acknowledgements
 

Último

Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilV3cube
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 

Último (20)

Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 

Oracle10g External Tables

  • 1. Oracle10g External Files An introduction to what is External Tables? 3/4/2010 For a Better Future 1
  • 2. Introduction  To have a better understanding of how External Table working in database.  By Kai Liu, Sr. Oracle Developer Kaitech, Inc. 3/4/2010 For a Better Future 2
  • 3. Topics of Discussion  History of External File usage?  Reading External Tables?  Writing External Tables? 3/4/2010 For a Better Future 3
  • 4. History of External File usage?  Previously the main method of getting external data into the database  Usually a disjointed process – File is put into a directory – Loader is run to load into temporary table – Validation is done on loaded rows  Problems? – Data File not found – Bad Format – rows not loaded – Have to load into character fields then validate to avoid bad formats – Separate steps mean coordination if first step fails or does not load all 3/4/2010 For a Better Future 4
  • 5. Control File options (errors=200,direct=true) load data replace into table TEMP_DAILY_ORDER_HEADERS WHEN REC_TYPE = ‘OH’ ( CUST_ID POSITION(001:008) INTEGER EXTERNAL, ORDER_ID POSITION(009:016) INTEGER EXTERNAL, ORDER_DATE POSITION(017:024) DATE FORMAT ‘YYYYMMDD’, NUM_DETAILS POSITION(025:030) INTEGER EXTERNAL, REC_TYPE POSITION(079:080) CHAR) into table TEMP_DAILY_ORDER_DETAILS WHEN REC_TYPE = ‘OD’ ( CUST_ID POSITION(001:008) INTEGER EXTERNAL, ORDER_ID POSITION(009:016) INTEGER EXTERNAL, LINE_NUM POSITION(017:020) INTEGER EXTERNAL, PRODUCT_ID POSITION(021:028) CHAR, QUANTITY POSITION(029:033) INTEGER EXTERNAL, PRICE POSITION(034:041) DECIMAL EXTERNAL, AMOUNT POSITION(042:050) DECIMAL EXTERNAL, DISCOUNT POSITION(051:057) DECIMAL EXTERNAL, NET_AMOUNT POSITION(058:066) DECIMAL EXTERNAL, REC_TYPE POSITION(079:080) CHAR) 3/4/2010 For a Better Future 5
  • 7. Reading External Tables? Started with Oracle 9i • External Files referenced directly from the database, as if they were tables • Uses ORACLE_LOADER driver • Define the file Directories • Tables are created with basic file format • SELECT used as if file is another table • Cannot INSERT, UPDATE or DELETE Let’s Demo 3/4/2010 For a Better Future 7
  • 8. Define Directory  Create directory where external data files are located – files must be in this area create directory external_dir as 'c:dataoracleextapp'; create directory external_bad_dir as 'c:dataoracleextapp'; Example in Unix: DROP DIRECTORY KMSDATA; CREATE OR REPLACE DIRECTORY KMSDATA AS '/home/oracle/data'; 3/4/2010 For a Better Future 8
  • 9. Create the Table Definitions Create table TEMP_PUBLICITY_NAME ( ACCT_NBR VARCHAR2(8), PUBLICITY_NAME1 VARCHAR2(30), PUBLICITY_NAME2 VARCHAR2(30) ) ORGANIZATION EXTERNAL (TYPE ORACLE_LOADER DEFAULT DIRECTORY dmsdata ACCESS PARAMETERS ( RECORDS DELIMITED BY newline BADFILE 'publname.bad' DISCARDFILE 'publname.dis' LOGFILE 'publname.log' FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '~' (ACCT_NBR CHAR, PUBLICITY_NAME1 CHAR, PUBLICITY_NAME2 CHAR) ) LOCATION ('PUBLNAME.txt') ) REJECT LIMIT UNLIMITED; / 3/4/2010 For a Better Future 9
  • 10. Sample Data File ~00002136~,~JANE DOE~,~AND PAPER INCORPORATED~ ~00017012~,~JOHN AND MARY~,~~ ~00017013~,~JOHN AND MARY~,~~ ~00043376~,~MRS MILLS~,~DO NOT ASK FOR PLEDGE-COVERED~ ~00043833~,~MRS NANCY~,~DO NOT ASK FOR PLEDGE-COVERED~ ~00051155~,~MRS JAMES~,~DO NOT ASK FOR PLEDGE-COVERED~ ~00051812~,~MRS WENDY~,~~ ~00057145~,~MRS CHARLES~,~DO NOT ASK FOR PLEDGE-COVERED~ ~00081234~,~HARRY~,~(MR STUART L PINKERT)~ ~06724967~,~MRS CAROL ~,~DO NOT SOLICIT EVER~ ~14660280~,~BRADEY FAMILY~,~(MR & MRS SMITH)~ 3/4/2010 For a Better Future 10
  • 11. Access the table Access the table with SQL SQL> select * from temp_publicity_name; ACCT_NBR PUBLICITY_NAME1 PUBLICITY_NAME2 -------- ------------------------------ ------------------------------ 00002136 JANE DOE AND PAPER INCORPORATED 00017012 JOHN & MARY 00017012 JOHN & MARY 00043376 MRS MILLS DO NOT ASK FOR 00043833 MRS NANCY DO NOT ASK FOR 00051155 MRS JAMES DO NOT ASK FOR 00051812 MRS WENDY 00057145 MRS CHARLES DO NOT ASK FOR 00081234 HARRY (MR STUART) 06724967 MRS CAROL DO NOT EVER 14660280 BRADY FAMILY (MR & MRS SMITH) You join good table with these Internal Table. 3/4/2010 For a Better Future 11
  • 12. Validate the table in PL/SQL Invalid format errors automatically go to the BAD file • How to validate the data? 1. Access the table and validate records that fail 1. Define bad file as external table with character records 2. Use PL/SQL to validate the bad records 2. Define the external table with character fields and validate the records before loading 3/4/2010 For a Better Future 12
  • 13. Check it Out! Check if the file exists: – File Name is missing from the directory – Rename custdata.csv to custdata_mistake.csv SQL> select count(*) from temp_publicity_name; select count(*) from temp_publicity_name *  ERROR at line 1:  ORA-29913: error in executing ODCIEXTTABLEOPEN callout  ORA-29400: data cartridge error  KUP-04040: file PUBLNAME.txt in DMSDATA not found  ORA-06512: at "SYS.ORACLE_LOADER", line 19– Rename file back to PUBLNAME.txt SQL> select count(*) from temp_publicity_name; COUNT(*) ---------- 25 – Can Use Exception Handling! 3/4/2010 For a Better Future 13
  • 14. Writing External Tables • New in Oracle 10g • Capability to write to an external table • Oracle-proprietary format • Can only be read by Oracle DB • Looks like an Export file • Can be created, then read • Uses ORACLE_DATAPUMP driver 3/4/2010 For a Better Future 14
  • 15. Write to External Files 3/4/2010 For a Better Future 15
  • 16. External Tables • External tables enable an application to import data from files and create output files for transfer to another Oracle database • Easier to follow SQL code than Loader control files 3/4/2010 For a Better Future 16
  • 17. Conclusion • External tables in 10g – if you are not using them, now is the time to start! • Loader is still around in 10g, but should no longer be used! • I still find massive amounts of SQL*Loader code in our current applications! • We should be using this now! 3/4/2010 For a Better Future 17
  • 18. Thank You  Q&A? 3/4/2010 For a Better Future 18