SQLLDR加载的数据中有换行符处理方法
1、创建测试表:
CREATE TABLE MANAGER( MGRNO NUMBER, MNAME VARCHAR2(30), JOB VARCHAR2(30), REMARK VARCHAR2(1000) );
2、创建控制文件
我们可以通过控制文件,在数据加载前处理remark列的数据,将用户指定的"
"字符替换为chr(10),即标准换行符,创建控制文件如下:
LOAD DATA INFILE 'D: estSqlLoaderldr_case11_1.dat' TRUNCATE INTO TABLE MANAGER FILELDS TERMINATED BY "," (MGRNO,MNAME,JOB,REMARK "REPLACE(:REMARK,'\n',CHR(10))" )
/*这里需要注意的是,替换时必须指定"\n"而不只是"
",因为"
"会被SQLLDR识 别成换行符并转换成换行标志,这样可能导致数据加载出错。而""是默认转义符,指定该转义符后SQLLDR
就会将"
"识别成普通字符了。*/
3、数据文件
保存为D: estSqlLoaderldr_case11_1.dat
10,SMITH,SALES MANAGER,This is SMITH. He is a Sales Manager. 11,ALLEN.W,TECH MANAGER,This is ALLEN.W. He is a Tech Manager. 16,BLAKE,HR MANAGER,This is BLAKE. He is a Hr Manager.
4、执行命令
C:UsersAdministrator>sqlldr scott/tiger@orcl control=D: estSqlLoaderldrTest.ctl SQL*Loader: Release 11.2.0.1.0 - Production on 星期二 12月 2 22:37:10 2014 Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved. 达到提交点 - 逻辑记录计数 3
5、查看结果
SQL> SELECT * FROM MANAGER; MGRNO MNAME JOB REMARK ---------- ------------------------------ ------------------- ---------------------------- 10 SMITH SALES MANAGER This is SMITH. He is a Sales Manager. 11 ALLEN.W TECH MANAGER This is ALLEN.W. He is a Tech Manager. 16 BLAKE HR MANAGER This is BLAKE. He is a Hr Manager