1. The control file contains the data to be loaded.
First, create a test table.
- SQL> showUser
- USERIs"ING"
- SQL>Create TableDept
- 2 (deptno number (10)ConstraintDept_pkPrimary Key,
- 3 dname varchar2 (20 ),
- 4 loc varchar2 (20 ));
- The table has been created.
Create a control file (including the loaded data)
- [Oracle @ linux sqlldr] $ pwd
- /U01/sqlldr
- [Oracle @ linux sqlldr] $ cat demo1.ctl
- LOADDATA
- INFILE *
- INTO TABLEDEPT
- FIELDS TERMINATEDBY ','
- (DEPTNO, DNAME, LOC)
- BEGINDATA
- 10, Sales, Virginia
- 20, Accounting, Virginia
- 30, Consulting, Virginia
- 40, Finance, Virginia
Then execute the load command in the command line.
- [Oracle @ linux sqlldr] $ pwd
- /U01/sqlldr
- [Oracle @ linux sqlldr] $ sqlldr userid = ing/ing control = demo1.ctl log = demo1.log
- SQL * Loader: Release 10.2.0.4.0-ProductionOnTuesday October 4 18:39:54 2011
- Copyright (c) 1982,200 7, Oracle.AllRights reserved.
- Submission point reached-logic record count 4
View dept table
- SQL>Select*FromDept;
- DEPTNO DNAME LOC
- --------------------------------------------------
- 10 Sales Virginia
- 20 Accounting Virginia
- 30 Consulting Virginia
- 40 Finance Virginia
View the demo1.log Log File
- [Oracle @ linux sqlldr] $ pwd
- /U01/sqlldr
- [Oracle @ linux sqlldr] $ cat demo1.log
- SQL * Loader: Release 10.2.0.4.0-ProductionOnTuesday October 4 18:39:54 2011
- Copyright (c) 1982,200 7, Oracle.AllRights reserved.
- Control File: demo1.ctl
- Data File: demo1.ctl
- Error file: demo1.bad
- Obsolete file: Not specified
- (All records can be discarded)
- Number of objects to be loaded:ALL
- Number of to be skipped: 0
- Allowed error: 50
- Bound array: 64 rows, up to 256000 bytes
- Continue: Unspecified
- Path used: General
- Table DEPT, loaded from each logical record
- Insert option for this tableINSERTEffective
- Column name location length abort packaging Data Type
- --------------------------------------------------------------------------
- DEPTNOFIRST*,CHARACTER
- DNAMENEXT*,CHARACTER
- LOCNEXT*,CHARACTER
- Table DEPT:
- Four rows are loaded successfully.
- Zero rows are not loaded due to data errors.
- Since allWHENClause failed. 0 rows are not loaded.
- Because all fields are empty, 0 rows are not loaded.
- Space allocated to the bound array: 49536 bytes (64 rows)
- Number of bytes read from the buffer: 1048576
- Total number of skipped logical records: 0
- Total number of logical records read: 4
- Total number of rejected logical records: 0
- Total number of discarded logical records: 0
- Starting from 18:39:54, January 1, 2011, Tuesday
- The operation ended at 18:39:54, January 1, October 04, 2011.
- Elapsed time: 00: 00: 00.68
- CPU time: 00: 00: 00.07
2. Separate control files from data files
Continue to use the previous dept table. First, create a control file and a data file.
- [Oracle @ linux sqlldr] $ pwd
- /U01/sqlldr
- [Oracle @ linux sqlldr] $ cat demo2.ctl
- LoadData
- Infile demo2.data
- AppendInto TableDept
- Fields terminatedBy ','
- (Deptno, dname, loc)
- [Oracle @ linux sqlldr] $ cat demo2.data
- 50, Sales, Virginia
- 60, Accounting, Virginia
- 70, Consulting, Virginia
- 80, Finance, Virginia
Then execute the load command in the command line.
- [Oracle @ linux sqlldr] $ sqlldr userid = ing/ing control = demo2.ctl
- SQL * Loader: Release 10.2.0.4.0-ProductionOnTuesday October 4 18:47:23 2011
- Copyright (c) 1982,200 7, Oracle.AllRights reserved.
- Submission point reached-logic record count 4
Finally, view the dept table.
- SQL>Select*FromDept;
- DEPTNO DNAME LOC
- --------------------------------------------------
- 10 Sales Virginia
- 20 Accounting Virginia
- 30 Consulting Virginia
- 40 Finance Virginia
- 50 Sales Virginia
- 60 Accounting Virginia
- 70 Consulting Virginia
- 80 Finance Virginia
- Eight rows have been selected.
3. Brief description of SQL * loader
Note: The number of braces on the left side of the code below is not part of the control file, just to facilitate display.
(1) LOAD DATA
(2) INFILE *
(3) INTO TABLE DEPT
(4) fields terminated ','
(5) (DEPTNO, DNAME, LOC)
(6) BEGINDATA
(7) 10, Sales, Virginia
(8) 20, Accounting, Virginia
(9) 30, Consulting, Virginia
(10) 40, Finance, Virginia
(1): This will tell sqlldr what to do. The above example indicates loading data.
(2): * indicates to load all the data (Example 1). You can also specify the name of the data file (Example 2 ).
(3): This will tell the table to which sqlldr is to be loaded. Complete Syntax: [insert | append | replace | truncate] into table dept insert-the default value is insert. The following dept table must be empty; append-append, the following dept table can not be blank; replace-is the first to delete and then insert; truncate-is the first to truncate and then insert.
(4): Tell sqlldr to separate values with commas.
(5) indicates that sqlldr data is to be loaded into the corresponding column.
(6): It indicates that sqlldr is about to load data.
(7 )~ (10): the specific data to be loaded.