sqlldr control file and parameter description detailed summary

Import command:

sqlldr user/password control=test.ctl skip=1 load=200000 errors=100 rows=1000  bindsize=33554432

Import command parameter description:

user/password  //数据库的用户名密码
control        //sqlldr控制文件位置
skip=1         //表示跳过第一行,从第二行开始导入
load=200000    //表示并不导入所有的数据,只导入跳过skip参数后的200000条数据
rows=1000     //表示一次加载的行数,默认值为64,此处设置为1000
errors=100    //表示出错100次后,停止加载
bindsize=33554432 //表示每次提交记录缓冲区的大小,默认256k

Control file:

load data
CHARACTERSET 'UTF8'            //指定字符集
infile '/home/datafile/test.txt'     //指定数据文件绝对路径
append into table test_tab    //指定导入库表
fields terminated by ',' ,'optionally enclosed by '|'    //字段之间的分隔值为逗号,界定符号为"|"
(
ID,                      //从数据文件中读取的字段列
DATA_DT Date "yyyy-mm-dd" ,        //设置日期格式
IMPDATE "to_date('2020-07-03 20:10:37','yyyy-mm-dd hh24:mi:ss')", //插入固定日期格式的值
FLAG constant"open"                      //constant指定插入默认值"open",不从指定的数据文件中读取
) 

Detailed explanation of control file related parameters:

  1. LOAD DATA: usually start with this, and the following parameters can be added before it:
  2. UNRECOVERABLE: indicates that the data is not recoverable
  3. RECOVERABLE: indicates that the data can be recovered
  4. CONTINUE_LOAD: means continue to add
  5. INFILE: indicates the location of the data file. If the value is *, the data is in the control file. In this example, there is no separate data file. For most loads, the data file is separated from the control file.
  6. INTO TABLE tbl_name: tbl_name is the target table to which the data will be loaded. This table must have been created before you execute the SQLLDR command.
    There are some interesting parameters to explain before INTO;
    INSERT: insert data into the table, the table must be empty, if the table is not empty, an error will be reported when executing the SQLLDR command, the default is the INSERT parameter.
    APPEND: Append data to the table, regardless of whether there is data in the table.
    REPLACE: Replace the data in the table, which is equivalent to first DELETE all the data in the table, and then INSERT.
    TRUNCATE: Similar to REPLACE, except that the DELETE method is not used to delete the data in the table, but the TRUNCATE method is used to delete, and then INSERT.
  7. FIELDS TERMINATED BY ",": Set the separation value of the data part of the string. Here, it is set as a comma (,) separation. Of course, it can also be replaced with any other visible characters, as long as it is the separator in the data line.
    (ENAME, JOB, SAL): The column name of the table to be inserted. It should be noted that the column name must be exactly the same as the column name in the table. The order of the columns can be different from the order of the columns in the table, but it must be the same as the column of the data part. One to one correspondence.
  8. The position keyword is used to specify the start and end positions of the column
    position(m:n): refers to the column value from the mth character to the nth character as the column value
    position( +2:15): the method of directly specifying the value is called absolute Offset, if you use a number, it is a relative offset, which means where the previous field ends, this time it starts, and you can do the calculation again with a relatively cheap amount.
    position(*) char(9): The advantage of this relative offset + type and length is that you only need to specify the starting position for the first column, and other columns only need to specify the column length.
  9. FILLER: Specify FILLER in the control file, indicating that the column value is not imported into the table.
  10. BEGINDATA: indicates that the following is the data to be loaded, only valid when INFILE is specified as *

Guess you like

Origin blog.csdn.net/weixin_49192027/article/details/107173780
Recommended