Load data into an exsit table
1. login as scott
2. create table sql_loader_test
SQL> create table sql_loader_test
(first varchar2(10),
last varchar2(10));
Table created.
3. create data file sql_loader_test.txt in folder /home/scott
$ cat sql_loader_test.txt
John,Watson
Roopesh,Ramklass
Sam,Alapati
4. create control file sql_loader_test.ctl in folder /home/scott
$ cat sql_loader_test.ctl
load data
infile ‘sql_loader_test.txt’
badfile ‘sql_loader_test.bad’
truncate
into table sql_loader_test
fields terminated by ‘,’
trailing nullcols
(first,last)
5. using command sqlldr to load data from file
$ sqlldr ‘scott/tiger’ control=‘sql_loader_test.ctl’
SQL*Loader: Release 12.1.0.2.0 - Production on Mon Jan 28 11:42:09 2019
Copyright © 1982, 2014, Oracle and/or its affiliates. All rights reserved.
Path used: Conventional
Commit point reached - logical record count 4
Table SQL_LOADER_TEST:
3 Rows successfully loaded.
Check the log file:
sql_loader_test.log
for more information about the load.
6. checking the table sql_loader_test
SQL> select * from sql_loader_test;
FIRST | LAST |
---|---|
John | Watson |
Roopesh | Ramklass |
Sam | Alapati |
creating one external table via sqlldr
7. create the external table file for the exsiting one
$ sqlldr scott/tiger control=‘sql_loader_test.ctl’ external_table=generate_only
SQL*Loader: Release 12.1.0.2.0 - Production on Mon Jan 28 13:52:52 2019
Copyright © 1982, 2014, Oracle and/or its affiliates. All rights reserved.
Path used: External Table
8. create specific pysical data file path from oracle side (grant access with DBA first)
SQL> grant create any directory to scott;
SQL> create directory system_dmp as ‘/home/scott’;
9. modify the auto-generation file with the property paramters
$ cat sql_loader_test.log
SQL> CREATE TABLE sql_loader_test_ext
(
“FIRST” VARCHAR2(10),
“LAST” VARCHAR2(10)
)
ORGANIZATION external
(
TYPE oracle_loader
DEFAULT DIRECTORY SYSTEM_DMP
ACCESS PARAMETERS
(
RECORDS DELIMITED BY NEWLINE CHARACTERSET US7ASCII
BADFILE ‘SYSTEM_DMP’:'sql_loader_test.bad’
LOGFILE 'sql_loader_test.log’
READSIZE 1048576
FIELDS TERMINATED BY “,” LDRTRIM
MISSING FIELD VALUES ARE NULL
REJECT ROWS WITH ALL NULL FIELDS
(
“FIRST” CHAR(255)
TERMINATED BY “,”,
“LAST” CHAR(255)
TERMINATED BY “,”
)
)
location
(
‘sql_loader_test.txt’
)
)REJECT LIMIT UNLIMITED;
10. testing the table available
SQL> select * from sql_loader_test_ext;
FIRST | LAST |
---|---|
John | Watson |
Roopesh | Ramklass |
Sam | Alapati |