1. Transfer the data into oracle using SQL* Loader Utility.
a) Loading comma-delimited data into oracle using SQL* Loader Utility.
STEP-1:- Create Data File employee.csv
105 Vishwa 7-Aug-1987 Finance 10000 A-29 Raj Apartment Satelite
112 Khushi 2-Apr-1988 Sales 8000 F-11 Dev Apartment Ghatlodia
100 Keyur 20-Jan-1985 Purchase 7800 C-5 Krishna Apartment Satelite
145 Heli 15-Dec-1990 Finance 9000 A-15 Shree Apartment Naranpura
250 Dhwanit 11-Sep-1987 Sales 12000 K-23 Seema Apartment Gota
STEP-2:- Open SQL Prompt Connect with any user and create a table
employee
create table employee
(empid number primary key,
empname varchar(30),
bdate date,
dept varchar(30),
salary number(7),
address varchar(80));
STEP-3:- Create a Control File employee.ctl
load data
infile 'employee.csv'
insert
into table employee
fields terminated by ','
(
empid integer external,
empname char,
bdate date "DD-MON-YYYY",
dept char,
salary integer external,
address char
)
STEP-4:- Open Command prompt and now SQL*Loader being invoked to
load this data:
E:\> sqlldr scott/tiger@orcl control=employee
b) Transfer only those data which belong to sales department into oracle
using SQL* Loader Utility. (Use Same data file and table)
STEP-1:- Create Data File employee.csv
STEP-2:- Open SQL Prompt Connect with any user and create a table
employee
STEP-3:- Create a Control File employee_sales.ctl
load data
infile 'employee.csv'
discardfile 'employee.dsc'
append
into table employee_sales when dept = 'Sales'
fields terminated by ','
(
empid integer external,
empname char,
bdate date "DD-MON-YYYY",
dept char,
salary integer external,
address char
)
STEP-4:- Open Command prompt and now SQL*Loader being invoked to
load this data:
E:\> sqlldr scott/tiger@orcl control=employee_sales
2. Append or Transfer this data into oracle using SQL* Loader
Utility (Concatenating physical records into one logical record)
STEP-1:- Create Data File employee_concate.dat
111;Reena;23-Aug-85;Purchase;11000;
"B-2 Keti Apartment Satelite"
221;Sahil;21-May-88;Sales;18000;
"A-1 Satya Apartment Gota"
225;Renu;30-Jan-90;Purchase;8000;
"K-5 Krishna Apartment Satelite"
148;Seema;5-Dec-89;Finance;8500;
"B-11 Shyam Apartment Naranpura"
150;Urmi;1-Sep-88;Sales;15000;
"C-25 Raj Apartment Ghatlodia"
STEP-2:- Open SQL Prompt Connect with any user and create a table
employee
STEP-3:- Create a Control File employee_concate.ctl
load data
infile 'employee_concate.dat'
append
concatenate 2
into table employee when dept= 'Finance'
fields terminated by ';' optionally enclosed by '"'
(
empid integer external,
empname char,
bdate date "DD-MON-YYYY",
dept char,
salary integer external,
address char
)
STEP-4:- Create a parameter file emp.par
userid=scott/oracle@orcl
control=employee.ctl
log=employee.log
STEP-5:- Open Command prompt and now SQL*Loader being invoked to
load this data:
E:\> sqlldr parfile=emp.par
3. Loading fixed-width data from two files into one oracle table
using SQL* Loader Utility. Also load null field data
STEP-1:- Create first Data File course1_Fixed.dat
101MCA11-jan-2000Master of Computer Application
102MCM15-may-2001Master of Computer Management
103BCA11-jan-2000
104BBA21-Apr-2005Bachlor of Business Management
Create second Data File course2_Fixed.dat
105MBA21-Apr-2005Master of Business Management
106BSC25-Feb-2008
106MSC25-Feb-2008Master of Science
STEP-2:- Open SQL Prompt Connect with any user and create a table course
create table course
(cid number,
cname varchar(3),
sdate date,
cdesc varchar(80));
STEP-3:- Create a Control File course.ctl
load data
infile 'course1_Fixed.dat'
badfile 'course1_Fixed.bad'
infile 'course2_Fixed.dat'
badfile 'course2_Fixed.bad'
insert
into table course trailing nullcols
(
cid position(1:3) integer external,
cname position(4:6) char,
sdate position(7:17) date "DD-MON-YYYY",
cdesc position(18:99) char
)
STEP-4:- Open Command prompt and now SQL*Loader being invoked to
load this data:
E:\> sqlldr scott/tiger@orcl control=course
4. Using expressions to transfer data into oracle using SQL* Loader
Utility but the contents of the empname field must be in the
upper case and the salary in this file are before increment and
you must add 10% increment in current salary and then you load
new data.
(NOTE: use below formula)
For Uppecase empname : "UPPER(:empname)"
For 10% increase salary : "(:salary + (:salary*0.10))"
STEP-1:- Create Data File employee_expr.dat
101,heena mehta,10000
102,reena patel,8000
103,seema patel,15000
104,keyur mehta,8500
105,dhwanit pandya,9000
106,heli shah,7000
107,vishwa verma,12000
108,khushi shah,11000
STEP-2:- Open SQL Prompt Connect with any user and create a table
employee_expr_data
create table employee_expr_data
(empid number,
empname varchar(30),
salary number(7));
STEP-3:- Create a Control File employee_expr.ctl
load data
infile 'employee_expr.dat'
append
into table employee_expr_data
(
empid integer external terminated by ',',
empname char terminated by ',' "UPPER(:empname)",
salary integer external terminated by ',' "(:salary +
(:salary*0.10))"
)
STEP-4:- Open Command prompt and now SQL*Loader being invoked to
load this data:
E:\> sqlldr scott/tiger@orcl control=employee_expr
5. Using expressions to transfer data into oracle using SQL* Loader
Utility add and calculate two fields total and per, the contents of
the sname field must be in the upper case and then you load
new data.
(NOTE: use below formula)
For total : ":marks1+:marks2+:marks3"
For per : "((:marks1+:marks2+:marks3)*100)/150"
Also use the FILLER keyword : The FILLER keyword has been used to specify
that SQL*Loader not load this field
STEP-1:- Create Data File student.csv
101 Vishwa BCA 34 30 41
102 Khushi MCA 44 32 33
103 Keyur BSCIT 21 36 22
104 Heli BCA 45 47 37
105 Dhwanit BSCIT 23 39 39
106 Heena MCA 35 43 40
107 Reena MCA 41 48 30
108 Seema MSCIT 42 31 25
STEP-2:- Open SQL Prompt Connect with any user and create two table
student and result
create table student
(sid number,
sname varchar(30),
course varchar(10));
create table result
(sid number,
marks1 number(2),
marks2 NUMBER(2),
marks3 number(2),
total number(3),
per number(4,2));
STEP-3:- Create a Control File student.ctl
load data
infile 'student.csv'
append
into table student fields terminated by ','
(
sid integer external,
sname char "UPPER(:sname)",
course char
)
into table result fields terminated by ',' trailing nullcols
(
sid position(1) integer external,
sname filler char,
course filler char,
marks1 integer external,
marks2 integer external,
marks3 integer external,
total integer external ":marks1+:marks2+:marks3",
per decimal external "((:marks1+:marks2+:marks3)*100)/150"
)
STEP-4:- Open Command prompt and now SQL*Loader being invoked to
load this data:
E:\> sqlldr scott/tiger@orcl control=student
6. Loading files into a large object column. You have the following
data in a file named product.csv, the description not contain in
pdesc field but the description of the product contain in
individual text file like note1.txt file, note2.txt and so on.. file
STEP-1:- Create Data File product.csv
101 Screw 2.25 note1.txt
102 Nut 5 note2.txt
103 Bolt 3.99 note3.txt
104 Hammer 9.99 note4.txt
105 Washer 1.99 note5.txt
note1.txt
110 quantity available It is very nice product
note2.txt
50 quantity aavailable and good product of this company
note3.txt
150 quantity aavailable and very small product
note4.txt
35 quantity aavailable and best quality
note5.txt
70 quantity aavailable and nice
STEP-2:- Open SQL Prompt Connect with any user and create a table
product
create table product
(pid NUMBER,
pname VARCHAR2(30),
price NUMBER(5,2),
pdesc clob);
STEP-3:- Create a Control File product.ctl
LOAD DATA
INFILE 'product.csv'
append
INTO TABLE product
FIELDS TERMINATED BY ','
(
pid integer external,
pname char,
price decimal external,
filename filler char,
pdesc LOBFILE (filename) TERMINATED BY EOF
)
STEP-4:- Open Command prompt and now SQL*Loader being invoked to
load this data:
E:\> sqlldr scott/tiger@orcl control=product
7. Concatenating records using CONTINUEIF Clause
STEP-1:- Create Data File
student1.dat
101,Heena Patel,Playing Reading,Naranpura|
102,Seema
Shah,Reading Traveling,Ghatlodia|
103,
Meena Patel,
Reading Traveling,Satellite|
104,Reeta Dave,Watching TV,Sola
student2.dat
_101,Heena Patel,
Playing Reading,Naranpura,
_102,
Seema Shah,Reading Traveling,Ghatlodia,
_103,Meena Patel,
Listening Traveling,Satellite,
_104,Reeta Dave,Watching TV,Sola
student3.dat
101,Heena
# Patel,Playing Reading,Naranpura,
102,Seema
# Shah,Reading
# Traveling,Ghatlodia,
103,Meena Patel,
# Listening Traveling,Satellite,
104,Reeta Dave,Watching TV,Sola
STEP-2:- Open SQL Prompt Connect with any user and create a table stud
create table stud
(sid number,
sname varchar(50),
hobbies varchar(50),
address varchar(100));
STEP-3:- Create a Control File student.ctl
load data
infile ‘student1.dat’
--infile ‘student2.dat’
--infile ‘student3.dat’
append
continueif last <> '|'
--continueif next preserve(1:1) = '#'
--continueif this (1) = '_'
into table stud
fields terminated by ',' trailing nullcols
(
sid integer external,
sname char,
hobbies char,
address char
)
STEP-4:- Open Command prompt and now SQL*Loader being invoked to
load this data:
E:\> sqlldr scott/tiger@orcl control=student