SlideShare a Scribd company logo
1 of 3
Oracle SQL Loader Utility
   Abstract
   The document is aimed at describing the procedure to be followed while working with SQL
   Loader Utility. Using the tool, we can load the external data coming in various formats like
   excel sheet, flat text file, comma Separated Variable (.csv) files and so on.
   Case History
   Database Administrators may come across some situation, where they need to load the
   external data coming from other sources into oracle tables. Before loading the data, they
   can restrict/limit/skip the loading with the usage of Control file (.ctl)

   Analysis
   External data will be of two types like Fixed Data and Variable Data and depending upon the
   type of the data, we need to generate the creation of the control file which in turn will
   convert the utility tool functioned as per the requirement and ensure that only the qualified
   or eligible data is loaded into the the Tables.

   Introduction: As discussed above, the data source will be in the form of various types like
   .csv and flat text files and hence the loading of the data into the tables has been classified
   into types namely Fixed Width and Varied data.

   Terminology:
1) Control File: Control file describes the actions to be done by the sql loader and we can use
   any text editor to writing a control file. Usually this will be followed by .ctl file extension.
2) In File: In file or input file is the name of the data source file like .csv or .txt which will be
   given as a input for the control file to look for the data.
3) Bad file: Bad file is the file which records the rows which got failed during the loading
   operation and the cause for the failure. This is a Optional file to provide while executing the
   sql loader at the command line
4) Discard File: Discard file is again an optional file, which will store the rows that are not
   qualified during the load operation, when a condition like where orwhen has been specified
   as a part of the control file.
5) Loading Options: INSERT, APPEND, REPLACE and TRUNCATE

   Insert         :    Loads rows only if the target table is empty.
   Append         :    Load rows if the target table is empty or not.
   Replace        :    First deletes all the rows in the table and then load rows
   Truncate        :    First truncates the table and then load rows.

   Varied Data Format ( .csv format or .txt files)
   Example:

   “10”,”James”,”1000”,”Finance”
   “20”,”Stuart”,”2000”,”Design”
   “30”,”Mclean”,”3000”,”Media”
   “40”,”Sandra”,”8000”,”Architect”
   “50”,”Natalie”,”9000”,”Solutions”

   Now we have to generate a control file to describe the loading actions for sqlloader utility to
   load the data into the table EMP as illustrated below:

   load data
infile „C:mineemp_data.csv‟
insert into table emp
fields terminated by “,” optionally enclosed by `” ` TRAILING NULLCOLS
( table_column1,
 Table_column2,
 Table_column3,
 Table_column4
)

Note: TRAILING NULLCOLS means if the last column is null then treat this as null value,
otherwise, SQL LOADER will treat the record as bad if the last column is null.

After you have written the control file save it and call SQL Loader utility by typing the
following command

$ sqlldr userid= scott/tiger control=emp.ctl log=emp_load.log

After you have executed the above command SQL Loader will shows you the output
describing how many rows it has loaded.

The LOG option of sql loader specifies where the log file of this sql loader session should be
created. The log file contains all actions which SQL loader has performed i.e. how many
rows were loaded, how many were rejected and how much time is taken to load the rows
and etc. You have to view this file for any errors encountered while running SQL Loader.

Fixed Data Format ( .dat file)
Example:
10 James 1000 Finance
20 Stuart 2000 Design
30 Mclean 3000 Media
10 Sandra 8000 Architect
20 Natalie 9000 Solutions
SOLUTION:
Steps :-
First Open the file in a text editor and count the length of fields, for above example,
employee number is from 1st position to 2nd position, employee name is from 4thposition to
10th position, Salary column is from 11th position to 15th position and finally Department
column from 16th postion to 21st Position.

load data
infile „C:mineemp_data.dat‟
insert into table emp
(
   table_column1      position(01:02)          integer external,
   table_column2      position(03:10)          char,
   table_column3      position(11:15)          integer external
   table_column4      position(16:21)          char
);
Note:- The datatypes (INTEGER EXTERNAL, CHAR, DECIMAL EXTERNAL) identify the
datatype of data fields in the file, not of corresponding columns in the table.

After writing the control file save it and initiate the SQL Loader utility by typing the following
command
$ sqlldr userid= scott/tiger control=emp.ctl log=emp_load.log

Loading Data into Multiple Tables using WHEN condition
We can simultaneously load data into multiple tables within the same session and using
WHEN condition to load only specified rows which meets a particular condition (only equal to
“=” and not equal to “<>” conditions are allowed).

Considering the above mentioned data, our requirement is to load the rows having
department number equals =10 into one table and department number not equal to <>
10 to go into another table.
load data
infile „C:mineemp_data.dat‟
append into table scott.emp1
when (dept_no=‟ 10‟)
(
   table_column1      position(01:02)    integer external,
   table_column2      position(03:10)    char,
   table_column3      position(11:15)    integer external
   table_column4      position(16:21)    char
)
Into table scott.emp2
when (dept_no<>‟ 10 ‟)
(
   table_column1      position(01:02)    integer external,
   table_column2      position(03:10)    char,
   table_column3      position(11:15)    integer external
   table_column4      position(16:21)    char
);

Note:-      SQL Loader help can be obtained by typing the command
                               $sqlldr help=Y
userid     ORACLE username/password
control    Control file name
log       Log file name
bad       Bad file name
data      Data file name
discard    Discard file name
discardmax Number of discards to allow
skip       Number of logical records to skip
load        Number of logical records to load
errors     Number of errors to allow
bindsize   Size of conventional path bind array in bytes
silent     Suppress messages during run direct, use direct path
parfile     parameter file: name of file that contains parameter specifications
parallel    do parallel load
file       File to allocate extents from
readsize     Size of Read buffer

More Related Content

What's hot

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
 
Multiple files single target single interface
Multiple files single target single interfaceMultiple files single target single interface
Multiple files single target single interfaceDharmaraj Borse
 
DataPump ile Single Parititon Export
DataPump ile Single Parititon ExportDataPump ile Single Parititon Export
DataPump ile Single Parititon ExportAnar Godjaev
 
Import and Export Big Data using R Studio
Import and Export Big Data using R StudioImport and Export Big Data using R Studio
Import and Export Big Data using R StudioRupak Roy
 
EBS R12 Concurrent program tracing
EBS R12 Concurrent program tracingEBS R12 Concurrent program tracing
EBS R12 Concurrent program tracingSachin Srivastava
 
Recipe 5 of Data Warehouse and Business Intelligence - The null values manage...
Recipe 5 of Data Warehouse and Business Intelligence - The null values manage...Recipe 5 of Data Warehouse and Business Intelligence - The null values manage...
Recipe 5 of Data Warehouse and Business Intelligence - The null values manage...Massimo Cenci
 
ata Warehouse and Business Intelligence - Recipe 7 - A messaging system for O...
ata Warehouse and Business Intelligence - Recipe 7 - A messaging system for O...ata Warehouse and Business Intelligence - Recipe 7 - A messaging system for O...
ata Warehouse and Business Intelligence - Recipe 7 - A messaging system for O...Massimo Cenci
 
ODI 11g - Multiple Flat Files to Oracle DB Table by taking File Name dynamica...
ODI 11g - Multiple Flat Files to Oracle DB Table by taking File Name dynamica...ODI 11g - Multiple Flat Files to Oracle DB Table by taking File Name dynamica...
ODI 11g - Multiple Flat Files to Oracle DB Table by taking File Name dynamica...Darshankumar Prajapati
 
Multiple Flat Files(CSV) to Target Table in ODI12c(12.2.1.0.0)
Multiple Flat Files(CSV) to Target Table in ODI12c(12.2.1.0.0)Multiple Flat Files(CSV) to Target Table in ODI12c(12.2.1.0.0)
Multiple Flat Files(CSV) to Target Table in ODI12c(12.2.1.0.0)Darshankumar Prajapati
 
Difference Between Sql - MySql and Oracle
Difference Between Sql - MySql and OracleDifference Between Sql - MySql and Oracle
Difference Between Sql - MySql and OracleSteve Johnson
 
Hechsp 001 Chapter 3
Hechsp 001 Chapter 3Hechsp 001 Chapter 3
Hechsp 001 Chapter 3Brian Kelly
 

What's hot (20)

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
 
Multiple files single target single interface
Multiple files single target single interfaceMultiple files single target single interface
Multiple files single target single interface
 
DataPump ile Single Parititon Export
DataPump ile Single Parititon ExportDataPump ile Single Parititon Export
DataPump ile Single Parititon Export
 
Etl2
Etl2Etl2
Etl2
 
Apps1
Apps1Apps1
Apps1
 
Sas classes in mumbai
Sas classes in mumbaiSas classes in mumbai
Sas classes in mumbai
 
Oracle notes
Oracle notesOracle notes
Oracle notes
 
Import and Export Big Data using R Studio
Import and Export Big Data using R StudioImport and Export Big Data using R Studio
Import and Export Big Data using R Studio
 
EBS R12 Concurrent program tracing
EBS R12 Concurrent program tracingEBS R12 Concurrent program tracing
EBS R12 Concurrent program tracing
 
Recipe 5 of Data Warehouse and Business Intelligence - The null values manage...
Recipe 5 of Data Warehouse and Business Intelligence - The null values manage...Recipe 5 of Data Warehouse and Business Intelligence - The null values manage...
Recipe 5 of Data Warehouse and Business Intelligence - The null values manage...
 
ata Warehouse and Business Intelligence - Recipe 7 - A messaging system for O...
ata Warehouse and Business Intelligence - Recipe 7 - A messaging system for O...ata Warehouse and Business Intelligence - Recipe 7 - A messaging system for O...
ata Warehouse and Business Intelligence - Recipe 7 - A messaging system for O...
 
Less17 Util
Less17  UtilLess17  Util
Less17 Util
 
ODI 11g - Multiple Flat Files to Oracle DB Table by taking File Name dynamica...
ODI 11g - Multiple Flat Files to Oracle DB Table by taking File Name dynamica...ODI 11g - Multiple Flat Files to Oracle DB Table by taking File Name dynamica...
ODI 11g - Multiple Flat Files to Oracle DB Table by taking File Name dynamica...
 
Multiple Flat Files(CSV) to Target Table in ODI12c(12.2.1.0.0)
Multiple Flat Files(CSV) to Target Table in ODI12c(12.2.1.0.0)Multiple Flat Files(CSV) to Target Table in ODI12c(12.2.1.0.0)
Multiple Flat Files(CSV) to Target Table in ODI12c(12.2.1.0.0)
 
Difference Between Sql - MySql and Oracle
Difference Between Sql - MySql and OracleDifference Between Sql - MySql and Oracle
Difference Between Sql - MySql and Oracle
 
Adbms
AdbmsAdbms
Adbms
 
Hechsp 001 Chapter 3
Hechsp 001 Chapter 3Hechsp 001 Chapter 3
Hechsp 001 Chapter 3
 
Mysqlppt
MysqlpptMysqlppt
Mysqlppt
 
Mysqlppt
MysqlpptMysqlppt
Mysqlppt
 
MySql slides (ppt)
MySql slides (ppt)MySql slides (ppt)
MySql slides (ppt)
 

Similar to Load data into Oracle tables using SQL Loader

Oracle sql tutorial
Oracle sql tutorialOracle sql tutorial
Oracle sql tutorialMohd Tousif
 
Introduction4 SQLite
Introduction4 SQLiteIntroduction4 SQLite
Introduction4 SQLiteStanley Huang
 
SSIS Project Profile
SSIS Project ProfileSSIS Project Profile
SSIS Project Profiletthompson0421
 
Unit-1 SQL fundamentals.docx SQL commands used to create table, insert values...
Unit-1 SQL fundamentals.docx SQL commands used to create table, insert values...Unit-1 SQL fundamentals.docx SQL commands used to create table, insert values...
Unit-1 SQL fundamentals.docx SQL commands used to create table, insert values...SakkaravarthiS1
 
moving data between the data bases in database
moving data between the data bases in databasemoving data between the data bases in database
moving data between the data bases in databasemqasimsheikh5
 
An overview of snowflake
An overview of snowflakeAn overview of snowflake
An overview of snowflakeSivakumar Ramar
 
Lecture on DBMS & MySQL.pdf v. C. .
Lecture on DBMS & MySQL.pdf v.  C.     .Lecture on DBMS & MySQL.pdf v.  C.     .
Lecture on DBMS & MySQL.pdf v. C. .MayankSinghRawat6
 
Chapter 3.pptx Oracle SQL or local Android database setup SQL, SQL-Lite, codi...
Chapter 3.pptx Oracle SQL or local Android database setup SQL, SQL-Lite, codi...Chapter 3.pptx Oracle SQL or local Android database setup SQL, SQL-Lite, codi...
Chapter 3.pptx Oracle SQL or local Android database setup SQL, SQL-Lite, codi...TAISEEREISA
 
Steps for upgrading the database to 10g release 2
Steps for upgrading the database to 10g release 2Steps for upgrading the database to 10g release 2
Steps for upgrading the database to 10g release 2nesmaddy
 
Sql smart reference_by_prasad
Sql smart reference_by_prasadSql smart reference_by_prasad
Sql smart reference_by_prasadpaddu123
 
Sql smart reference_by_prasad
Sql smart reference_by_prasadSql smart reference_by_prasad
Sql smart reference_by_prasadpaddu123
 
Automating Test File Creation
Automating Test File CreationAutomating Test File Creation
Automating Test File Creationbdebruin
 

Similar to Load data into Oracle tables using SQL Loader (20)

Sql intro & ddl 1
Sql intro & ddl 1Sql intro & ddl 1
Sql intro & ddl 1
 
Sql intro & ddl 1
Sql intro & ddl 1Sql intro & ddl 1
Sql intro & ddl 1
 
Sql lite android
Sql lite androidSql lite android
Sql lite android
 
Oracle sql tutorial
Oracle sql tutorialOracle sql tutorial
Oracle sql tutorial
 
SQL
SQLSQL
SQL
 
Introduction4 SQLite
Introduction4 SQLiteIntroduction4 SQLite
Introduction4 SQLite
 
Sql
SqlSql
Sql
 
SSIS Project Profile
SSIS Project ProfileSSIS Project Profile
SSIS Project Profile
 
Unit-1 SQL fundamentals.docx SQL commands used to create table, insert values...
Unit-1 SQL fundamentals.docx SQL commands used to create table, insert values...Unit-1 SQL fundamentals.docx SQL commands used to create table, insert values...
Unit-1 SQL fundamentals.docx SQL commands used to create table, insert values...
 
Sqlldr examples
Sqlldr examplesSqlldr examples
Sqlldr examples
 
moving data between the data bases in database
moving data between the data bases in databasemoving data between the data bases in database
moving data between the data bases in database
 
An overview of snowflake
An overview of snowflakeAn overview of snowflake
An overview of snowflake
 
ADVANCE ITT BY PRASAD
ADVANCE ITT BY PRASADADVANCE ITT BY PRASAD
ADVANCE ITT BY PRASAD
 
Lecture on DBMS & MySQL.pdf v. C. .
Lecture on DBMS & MySQL.pdf v.  C.     .Lecture on DBMS & MySQL.pdf v.  C.     .
Lecture on DBMS & MySQL.pdf v. C. .
 
Chapter 3.pptx Oracle SQL or local Android database setup SQL, SQL-Lite, codi...
Chapter 3.pptx Oracle SQL or local Android database setup SQL, SQL-Lite, codi...Chapter 3.pptx Oracle SQL or local Android database setup SQL, SQL-Lite, codi...
Chapter 3.pptx Oracle SQL or local Android database setup SQL, SQL-Lite, codi...
 
Steps for upgrading the database to 10g release 2
Steps for upgrading the database to 10g release 2Steps for upgrading the database to 10g release 2
Steps for upgrading the database to 10g release 2
 
Sq lite
Sq liteSq lite
Sq lite
 
Sql smart reference_by_prasad
Sql smart reference_by_prasadSql smart reference_by_prasad
Sql smart reference_by_prasad
 
Sql smart reference_by_prasad
Sql smart reference_by_prasadSql smart reference_by_prasad
Sql smart reference_by_prasad
 
Automating Test File Creation
Automating Test File CreationAutomating Test File Creation
Automating Test File Creation
 

Recently uploaded

08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphNeo4j
 
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your BudgetHyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your BudgetEnjoy Anytime
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhisoniya singh
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksSoftradix Technologies
 
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
 
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
 
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxMaking_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxnull - The Open Security Community
 
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
 
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?XfilesPro
 
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
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
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
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 

Recently uploaded (20)

08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
 
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your BudgetHyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping Elbows
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other Frameworks
 
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
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptxVulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
 
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxMaking_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
 
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
 
The transition to renewables in India.pdf
The transition to renewables in India.pdfThe transition to renewables in India.pdf
The transition to renewables in India.pdf
 
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?
 
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
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
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
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 

Load data into Oracle tables using SQL Loader

  • 1. Oracle SQL Loader Utility Abstract The document is aimed at describing the procedure to be followed while working with SQL Loader Utility. Using the tool, we can load the external data coming in various formats like excel sheet, flat text file, comma Separated Variable (.csv) files and so on. Case History Database Administrators may come across some situation, where they need to load the external data coming from other sources into oracle tables. Before loading the data, they can restrict/limit/skip the loading with the usage of Control file (.ctl) Analysis External data will be of two types like Fixed Data and Variable Data and depending upon the type of the data, we need to generate the creation of the control file which in turn will convert the utility tool functioned as per the requirement and ensure that only the qualified or eligible data is loaded into the the Tables. Introduction: As discussed above, the data source will be in the form of various types like .csv and flat text files and hence the loading of the data into the tables has been classified into types namely Fixed Width and Varied data. Terminology: 1) Control File: Control file describes the actions to be done by the sql loader and we can use any text editor to writing a control file. Usually this will be followed by .ctl file extension. 2) In File: In file or input file is the name of the data source file like .csv or .txt which will be given as a input for the control file to look for the data. 3) Bad file: Bad file is the file which records the rows which got failed during the loading operation and the cause for the failure. This is a Optional file to provide while executing the sql loader at the command line 4) Discard File: Discard file is again an optional file, which will store the rows that are not qualified during the load operation, when a condition like where orwhen has been specified as a part of the control file. 5) Loading Options: INSERT, APPEND, REPLACE and TRUNCATE Insert : Loads rows only if the target table is empty. Append : Load rows if the target table is empty or not. Replace : First deletes all the rows in the table and then load rows Truncate : First truncates the table and then load rows. Varied Data Format ( .csv format or .txt files) Example: “10”,”James”,”1000”,”Finance” “20”,”Stuart”,”2000”,”Design” “30”,”Mclean”,”3000”,”Media” “40”,”Sandra”,”8000”,”Architect” “50”,”Natalie”,”9000”,”Solutions” Now we have to generate a control file to describe the loading actions for sqlloader utility to load the data into the table EMP as illustrated below: load data
  • 2. infile „C:mineemp_data.csv‟ insert into table emp fields terminated by “,” optionally enclosed by `” ` TRAILING NULLCOLS ( table_column1, Table_column2, Table_column3, Table_column4 ) Note: TRAILING NULLCOLS means if the last column is null then treat this as null value, otherwise, SQL LOADER will treat the record as bad if the last column is null. After you have written the control file save it and call SQL Loader utility by typing the following command $ sqlldr userid= scott/tiger control=emp.ctl log=emp_load.log After you have executed the above command SQL Loader will shows you the output describing how many rows it has loaded. The LOG option of sql loader specifies where the log file of this sql loader session should be created. The log file contains all actions which SQL loader has performed i.e. how many rows were loaded, how many were rejected and how much time is taken to load the rows and etc. You have to view this file for any errors encountered while running SQL Loader. Fixed Data Format ( .dat file) Example: 10 James 1000 Finance 20 Stuart 2000 Design 30 Mclean 3000 Media 10 Sandra 8000 Architect 20 Natalie 9000 Solutions SOLUTION: Steps :- First Open the file in a text editor and count the length of fields, for above example, employee number is from 1st position to 2nd position, employee name is from 4thposition to 10th position, Salary column is from 11th position to 15th position and finally Department column from 16th postion to 21st Position. load data infile „C:mineemp_data.dat‟ insert into table emp ( table_column1 position(01:02) integer external, table_column2 position(03:10) char, table_column3 position(11:15) integer external table_column4 position(16:21) char ); Note:- The datatypes (INTEGER EXTERNAL, CHAR, DECIMAL EXTERNAL) identify the datatype of data fields in the file, not of corresponding columns in the table. After writing the control file save it and initiate the SQL Loader utility by typing the following command
  • 3. $ sqlldr userid= scott/tiger control=emp.ctl log=emp_load.log Loading Data into Multiple Tables using WHEN condition We can simultaneously load data into multiple tables within the same session and using WHEN condition to load only specified rows which meets a particular condition (only equal to “=” and not equal to “<>” conditions are allowed). Considering the above mentioned data, our requirement is to load the rows having department number equals =10 into one table and department number not equal to <> 10 to go into another table. load data infile „C:mineemp_data.dat‟ append into table scott.emp1 when (dept_no=‟ 10‟) ( table_column1 position(01:02) integer external, table_column2 position(03:10) char, table_column3 position(11:15) integer external table_column4 position(16:21) char ) Into table scott.emp2 when (dept_no<>‟ 10 ‟) ( table_column1 position(01:02) integer external, table_column2 position(03:10) char, table_column3 position(11:15) integer external table_column4 position(16:21) char ); Note:- SQL Loader help can be obtained by typing the command $sqlldr help=Y userid ORACLE username/password control Control file name log Log file name bad Bad file name data Data file name discard Discard file name discardmax Number of discards to allow skip Number of logical records to skip load Number of logical records to load errors Number of errors to allow bindsize Size of conventional path bind array in bytes silent Suppress messages during run direct, use direct path parfile parameter file: name of file that contains parameter specifications parallel do parallel load file File to allocate extents from readsize Size of Read buffer