Step 1
Create a table in Oracle with the same structure as in the CSV file by taking appropriate datatypes. For example, create a table like this:
LINUX> sqlplus user/password
SQL> CREATE TABLE jobs
(
st varchar2(2),
occ_code varchar2(7),
occ_title varchar2(30),
tot_emp number(10),
a_mean number(10,2),
a_pct10 number(10,2),
a_pct25 number(10,2),
a_median number(10,2),
a_pct75 number(10,2),
a_pct100 number(10,2)
);
Step 2
After creating the table, you have to write a control file describing the actions which SQL Loader should do. You can use any text editor to write the control file. Now let us write a controlfile.
LINUX> vi jobs.ctl
LOAD DATA
INFILE ‘/home/oracle/jobs.csv’
BADFILE ‘/home/oracle/*user*/jobs.bad’
DISCARDFILE ‘/home/oracle/*user*/jobs.dsc’
INSERT INTO TABLE emp
FIELDS TERMINATED BY “,”
OPTIONALLY ENCLOSED BY ‘”’ TRAILING NULLCOLS
(empno,name,sal,jdate date ‘mm/dd/yyyy’)
Step 3
After you have wrote the control file save it and then, call SQL Loader utility by typing the following command
LINUX> sqlldr userid=user/password control=jobs.ctl log=jobs.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 sqlldr 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.