Thursday, September 6, 2012

SQL Loader

All you need is CTL file, data file and the table to put in the data

Control File (Test.ctl)

LOAD DATA
TRUNCATE
INTO TABLE EMP
FIELDS TERMINATED BY "," OPTIONALLY ENCLOSED BY '"' TRAILING NULLCOLS
(
emp_id "trim(:emp_id)",
emp_name "trim(:emp_name)",
emp_dept "trim(:emp_dept)"
)

Data file would be (Test.csv)

emp_id,emp_name,emp_dept
1,John,10
2,Jane,30

Go to the command Prompt and type

C:\ >sqlldr.exe userid=scott/tiger@oradb control=c:\sqldrtest\TEST.ctl log= c:\sqldrtest\20110922.LOG bad= c:\sqldrtest\20110922.BAD data= c:\sqldrtest\Test.csv errors=1000

SQL*Loader: Release 10.2.0.4.0 - Production on Thu Sep 22 11:08:02 2011

Copyright (c) 1982, 2007, Oracle.  All rights reserved.

Commit point reached - logical record count 2

It is always a good practice to have Errors=0, so that the file does not get processed even if there is one error

No comments:

Post a Comment