Sunday, 27 December 2015

Step by Step SQL Loader in Oracle with example

Step 1: Create a txt file named employee.txt

[oracle@saidrasel ~]$ pwd
/home/oracle
[oracle@saidrasel ~]$ vim employee.txt
101,Karim,Sales,5000
201,Rahim,Technology,5500
301,David,Technology,7000
401,Nisha,Marketing,9500
501,Sirat,Technology,6000
601,Ritu,Accounting,5400

[oracle@saidrasel ~]$ cat employee.txt
101,Karim,Sales,5000
201,Rahim,Technology,5500
301,David,Technology,7000
401,Nisha,Marketing,9500
501,Sirat,Technology,6000
601,Ritu,Accounting,5400
[oracle@saidrasel ~]$

Step 2: Create a control file named example1.ctl

[oracle@saidrasel ~]$ vim example1.ctl

load data
 infile '/home/oracle/employee.txt'
 into table employee
 fields terminated by ","
 ( id, ename, deptno, salary )

[oracle@saidrasel ~]$ cat example1.ctl
load data
 infile '/home/oracle/employee.txt'
 into table employee
 fields terminated by ","
 ( id, ename, deptno, salary )
[oracle@saidrasel ~]$

Step 3: Create a table named employee where data will be loaded 

SQL> create table employee
(
  id integer,
  ename varchar2(10),
  deptno varchar2(15),
  salary integer
)

Step 4: Execute the sql loader command 

[oracle@saidrasel ~]$ sqlldr system/ control=/home/oracle/example1.ctl

SQL*Loader: Release 11.2.0.3.0 - Production on Mon Dec 28 12:57:29 2015

Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.

Commit point reached - logical record count 6
[oracle@saidrasel ~]$

Step 5: Now check that data is loaded or not???

Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL> select * from employee;

        ID ENAME      DEPTNO              SALARY
---------- ---------- --------------- ----------
       101 Karim      Sales                 5000
       201 Rahim      Technology            5500
       301 David      Technology            7000
       401 Nisha      Marketing             9500
       501 Sirat      Technology            6000
       601 Ritu       Accounting            5400

6 rows selected.

SQL>

No comments:

Post a Comment