Skip to Main Content
  • Questions
  • Purpose of clauses in SQL*Loader control file

Breadcrumb

Question and Answer

Chris Saxon

Thanks for the question.

Asked: March 15, 2017 - 2:25 pm UTC

Last updated: March 16, 2017 - 3:22 pm UTC

Version: 11g

Viewed 1000+ times

You Asked

Hi,

I am Learning Data Loading With Sql Loader.i written some basic control files(with out using Clauses) then data loaded well. but i did not understand the clauses like NULLIF, CHAR, DEFAULTIF etc. So please tell me why we use this Clauses in Control File. For Example below is the control file for reference.

====================================================
OPTIONS (SKIP = 1)
LOAD DATA CHARACTERSET WE8MSWIN1252
INFILE '$FILE'
APPEND
INTO TABLE Customer_table
FIELDS TERMINATED BY '|'
TRAILING NULLCOLS
(
"SOURCE_SYSTEM_NAME" CHAR NULLIF "SOURCE_SYSTEM_NAME"=BLANKS,
"OPERATING_UNIT" CHAR NULLIF "OPERATING_UNIT"=BLANKS,
"CUSTOMER_NAME" CHAR NULLIF "CUSTOMER_NAME"=BLANKS,
"LEGACY_CUSTOMER_NUMBER" CHAR NULLIF "LEGACY_CUSTOMER_NUMBER"=BLANKS,
"CUST_ACCT_NAME" CHAR NULLIF "CUST_ACCT_NAME"=BLANKS,
"SITE_NAME" CHAR NULLIF "SITE_NAME"=BLANKS,
"SITE_USAGE" CHAR NULLIF "SITE_USAGE"=BLANKS,
"CONTACT_FIRST_NAME" CHAR NULLIF "CONTACT_FIRST_NAME"=BLANKS,
"CONTACT_LAST_NAME" CHAR NULLIF "CONTACT_LAST_NAME"=BLANKS,
"CONTACT_EMAIL" CHAR NULLIF "CONTACT_EMAIL"=BLANKS,
"CONTACT_ROLE" CHAR NULLIF "CONTACT_ROLE"=BLANKS,
"CONTACT_PHONE" CHAR NULLIF "CONTACT_PHONE"=BLANKS,
"MOBILE_NUMBER" CHAR NULLIF "MOBILE_NUMBER"=BLANKS,
"FAX_NUMBER" CHAR NULLIF "FAX_NUMBER"=BLANKS,
"PHONE_COUNTRY_CODE" CHAR NULLIF "PHONE_COUNTRY_CODE"=BLANKS,
"PHONE_AREA_CODE" CHAR NULLIF "PHONE_AREA_CODE"=BLANKS,
CONTACT_STATUS "Trim(Replace(:CONTACT_STATUS, chr(13), ''))",
CREATED_BY "FND_GLOBAL.LOGIN_ID",
CREATION_DATE sysdate,
LAST_UPDATED_BY "FND_GLOBAL.LOGIN_ID",
LAST_UPDATE_DATE sysdate,
Last_Update_Login "FND_GLOBAL.LOGIN_ID"
)

===============================================
I loaded data by removing null if and char second time keeping them but i did not notice any difference between them.

and Chris said...

CHAR specifies the data type for the field as character. This is the default.

NULLIF sets the field to null if the condition is met. So:

NULLIF "FIELD"=BLANKS


It says "if the FIELD is blank, set it to null".

If DEFAULTIF condition is true, Oracle sets the field to zero if the data is numeric. If it's non-numeric, it's set to null.

The relationship between NULLIF and DEFAULTIF is complicated. The documentation explains how these work:

http://docs.oracle.com/database/122/SUTIL/oracle-sql-loader-field-list-contents.htm#SUTIL1202

For full details on what all the clauses are and there uses, read the docs:

http://docs.oracle.com/database/122/SUTIL/oracle-sql-loader-field-list-contents.htm#SUTIL006

Is this answer out of date? If it is, please let us know via a Comment