1. Simple example of SQLLDR data loading
1. Create a sample data table
create table TS_USER
(
id VARCHAR2(20),
user_name VARCHAR2(30),
password VARCHAR2(50),
sex CHAR(1),
create_time DATE
)
2. Create a control file data.ctl in the E drive, the content is as follows:
LOAD DATA
INFILE 'data.txt'
APPEND INTO TABLE TS_USER
FIELDS TERMINATED BY ','
(ID, USER_NAME, PASSWORD)
3. Create a data file data.txt in the E drive, the content is as follows:
1,tuozixuan,123456
2,wengpeng,password
4. Load the data in the data file data.txt into the local database
sqlldr userid=scott/[email protected]/orcl control=data.ctl
Second, the main parameters of the sqlldr command
userid: oracle username/password
control: control file name
data: data file name
log: log file name
bad: bad filename
skip: number of logical records to skip (default 0)
load: the number of logical records to load (default all)
sqlldr userid=scott/[email protected]/orcl control=data.ctl data=data.txt log=log.log bad=bad.log skip=1 load=1
3. Description of the control file
1. LOAD DATA
Control file identification
2. INFILE 'data.txt'
Specify the data file to be imported as data.txt
If INFILE * is used, it means that the data to be imported is in the control file, that is, the content after BEGINDATA.
3. APPEND INTO TABLE TS_USER
Specify the table to load the data into. The loading methods are as follows:
APPEND: If there is data in the original table, append it to the table
INSERT: Load data into an empty table. If there is data in the original table, it will stop loading. This item is the default value.
REPLACE: If there is data in the original table, it will be deleted all
TRUNCATE: If there is data in the original table, it will be deleted with the truncate statement
4. FIELDS TERMINATED BY ','
Delimiter of specified data
FIELDS TERMINATED BY WHITESPACE: split on whitespace
FIELDS TERMINATED BY X'09': split by tab
TRAILINGNULLCOLS: Indicates that the field is allowed to be empty when there is no corresponding value
5. (ID, USER_NAME, PASSWORD)
table fields
question:
1. SQL*Loader-601: For INSERT option, table must be empty. Error on table TS_USER
Use the INSERT option to import (the default is the INSERT option if you don't fill in), there is no data in the imported table, you can empty the table or use the APPEND option according to the specific situation.