oracle sqluldr2 工具 安装使用
--下载:sqluldr2_linux_jb51.rar
下载完sqluldr解压后,文件夹内容如下:
sqluldr2.exe 用于32位windows平台;
sqluldr2_linux32_10204.bin 适用于linux32位操作系统;
sqluldr2_linux64_10204.bin 适用于linux64位操作系统;
sqluldr264.exe 用于64位windows平台。
---一、安装 sqluldr2 工具
cd /home/oracle/tools
unzip sqluldr2_linux_jb51.rar
---使用linux64位 sqluldr2_linux64_10204.bin
mv sqluldr2_linux64_10204.bin sqluldr2
---赋予执行权限
chmod +x sqluldr2
--添加环境变量
vi .bash_profile
export LD_LIBRARY_PATH=$ORACLE_HOME/bin:$ORACLE_HOME/lib:/lib:/usr/lib
LD_LIBRARY_PATH=$ORACLE_HOME/lib
LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:$ORACLE_HOME/oracm/lib
LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:/lib:/usr/lib:/usr/local/lib
export LD_LIBRARY_PATH
---在安装目录下执行 sqluldr2 看到如下结果,表示安装成功!
[oracle@test-zdhcsdb tools]$ sqluldr2
SQL*UnLoader: Fast Oracle Text Unloader (GZIP, Parallel), Release 4.0.1
(@) Copyright Lou Fangxin (AnySQL.net) 2004 - 2010, all rights reserved.
License: Free for non-commercial useage, else 100 USD per server.
Usage: SQLULDR2 keyword=value [,keyword=value,...]
Valid Keywords:
user = username/password@tnsname
sql = SQL file name
query = select statement
field = separator string between fields
record = separator string between records
rows = print progress for every given rows (default, 1000000)
file = output file name(default: uldrdata.txt)
log = log file name, prefix with + to append mode
fast = auto tuning the session level parameters(YES)
text = output type (MYSQL, CSV, MYSQLINS, ORACLEINS, FORM, SEARCH).
charset = character set name of the target database.
ncharset= national character set name of the target database.
parfile = read command option from parameter file
for field and record, you can use '0x' to specify hex character code,
\r=0x0d \n=0x0a |=0x7c ,=0x2c, \t=0x09, :=0x3a, #=0x23, "=0x22 '=0x27
---二、在sqluldr2命令行下执行导出
[oracle@test tools]$ ls
csv.log data data.log scripts.txt sql.file sqluldr2
---三、编辑SQL文件
vi sql.file
SELECT A.* FROM TEST.T_TEST_TA A
LEFT JOIN TEST.T_TEST_SF F
ON F.KN = A.ID
AND F.S_DT BETWEEN '20180501' AND '20180531'
WHERE A.T_DT BETWEEN '20180501' AND '20180531'
AND D.RY = '01';
---执行命令
--生产N个40M 的文件
time sqluldr2 user=test/123456 sql=sql.file field=0x2c record=0x0d0x0a size=40M text=CSV safe=Yes file=./data/csv201805_%b.csv fast=yes log=csv.log charset=ZHS16GBK
---生成一个文件
time sqluldr2 user=test/123456 sql=sql.file field=0x2c record=0x0d0x0a text=CSV safe=Yes file=./data/csv201805.csv fast=yes log=csv.log charset=ZHS16GBK
主要参数说明
Field 分隔符 指定字段分隔符,默认为逗号
record 分隔符 指定记录分隔符,默认为回车换行,Windows下的换行
quote 引号符 指定非数字字段前后的引号符
例如现在要改变默认的字段分隔符,用“#”来分隔记录,导出的命令如下所示:
sqluldr2 test/test sql=tmp.sql field=#
在指定分隔符时,可以用字符的ASCII代码(0xXX,大写的XX为16进制的ASCII码值)来指定一个字符,常用的字符的ASCII代码如下:
回车=0x0d,换行=0x0a,TAB键=0x09,|=0x7c,&=0x26,双引号=0x22,单引号=0x27
在选择分隔符时,一定不能选择会在字段值中出现的字符