DEV Community

Pranav Bakare
Pranav Bakare

Posted on • Edited on

Working of SQL*Loader

Working of SQL*Loader (Short Overview)

SQL*Loader is a utility that facilitates the bulk loading of data from external files into Oracle tables. It works by reading data from external files (e.g., CSV, text files) and inserting it into database tables as per the instructions in a control file.

Key Components in SQL*Loader:

1. Control File:

The control file (.ctl) defines how data from the external file should be mapped into the Oracle database.

It contains details such as:

  • The path to the data file.
  • The name of the target table in the database.
  • The structure of the data (field delimiters, date formats, etc.).
  • How to handle special cases like field enclosure or null values.

Example:

LOAD DATA
INFILE 'employees.csv'
INTO TABLE employees
FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"'
(
  emp_id,
  first_name,
  last_name,
  email,
  phone_number,
  hire_date DATE "YYYY-MM-DD",
  salary
)

Enter fullscreen mode Exit fullscreen mode

2. Data File:

This is the external file (e.g., employees.csv) containing the data to be loaded into the Oracle database.

  • It typically has data in a structured format (e.g., CSV, fixed-width).

3. Bad File:

The bad file (.bad) stores records from the data file that SQL*Loader couldn't load due to errors (e.g., invalid data or incorrect formats).

  • These records are not inserted into the table, and the bad file allows you to review and correct them.

4. Discard File:

The discard file (.dsc) contains records that were rejected based on user-defined conditions (such as constraints or triggers). These records are valid in the data file but fail to meet the table’s integrity constraints.


5. Log File:

The log file (.log) is generated during the loading process and provides a detailed report of the operations, including how many records were successfully loaded, how many failed, and any errors encountered.


Workflow of SQL*Loader:

  • 1. Prepare the Data File: The data file contains the records to be loaded.
  • 2. Create the Control File: The control file defines how data is interpreted and loaded into the database.
  • 3. Run SQL*Loader: The sqlldr command is executed, using the control file to direct the data loading process.
  • 4. Monitor Results: The log, bad, and discard files provide feedback on the process.
  • 5. Verify Data: Finally, the loaded data can be verified in the Oracle table.

This efficient mechanism allows SQL*Loader to handle large-scale data imports into Oracle databases.

Top comments (0)