1.使用介绍
SQL*UnLoader: Fast Oracle Text Unloader (GZIP, Parallel), Release 4.0.1
(@) Copyright Lou Fangxin (AnySQL.net) 2004 - 2010, all rights reserved.
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
read = set DB_FILE_MULTIBLOCK_READ_COUNT at session level
sort = set SORT_AREA_SIZE at session level (UNIT:MB)
hash = set HASH_AREA_SIZE at session level (UNIT:MB)
array = array fetch size
head = print row header(Yes|No)
batch = save to new file for every rows batch (Yes/No)
size = maximum output file piece size (UNIB:MB)
serial = set _serial_direct_read to TRUE at session level
trace = set event 10046 to given level at session level
table = table name in the sqlldr control file
control = sqlldr control file and path.
mode = sqlldr option, INSERT or APPEND or REPLACE or TRUNCATE
buffer = sqlldr READSIZE and BINDSIZE, default 16 (MB)
long = maximum long field size
width = customized max column width (w1:w2:...)
quote = optional quote string
data = disable real data unload (NO, OFF)
alter = alter session SQLs to be execute before unload
safe = use large buffer to avoid ORA-24345 error (Yes|No)
crypt = encrypted user information only (Yes|No)
sedf/t = enable character translation function
null = replace null with given value
escape = escape character for special characters
escf/t = escape from/to characters list
format = MYSQL: MySQL Insert SQLs, SQL: Insert SQLs.
exec = the command to execute the SQLs.
prehead = column name prefix for head line.
rowpre = row prefix string for each line.
rowsuf = row sufix string for each line.
colsep = separator string between column name and value.
presql = SQL or scripts to be executed before data unload.
postsql = SQL or scripts to be executed after data unload.
lob = extract lob values to single file (FILE).
lobdir = subdirectory count to store lob files .
split = table name for automatically parallelization.
degree = parallelize data copy degree (2-128).
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
2.常用案例
根据查询语句导出
sqluldr2_linux64_10204.bin user="username/pwd" query="select * from table" field="0x09" record=0x0a file="/opt/data/table.txt" charset=UTF8
如果查询sql比较长,则可以把sql语句放入到文件中
sqluldr2_linux64_10204.bin user="username/pwd" sql="/opt/sql/query.sql" field="0x09" record=0x0a file="/opt/data/table.txt" charset=UTF8
按记录数切分文件的功能取决于三个命令行选项: FILE, ROWS, BATCH. 其中FILE选项指定的文件名中需要包括”%b”特征串, 以表示生成的文件号. ROWS指定单个文件的记录数, 而BATCH则指定是否切换成多个文件.
sqluldr2_linux64_10204.bin user="username/pwd" sql="/opt/sql/query.sql" field="0x09" record=0x0a rows=100000 batch=yes file="/opt/data/table.%b.txt" charset=UTF8
按大小切分文件的功能取决于两个命令行选项: FILE, SIZE. 其中FILE选项指定的文件名中需要包括”%b”特征串, 以表示生成的文件号; 而SIZE选项指定每个文件的目标大小.
sqluldr2_linux64_10204.bin user="username/pwd" sql="/opt/sql/query.sql" field="0x09" record=0x0a size=500MB file="/opt/data/table.%b.txt" charset=UTF8
3.常见错误
sqluldr2_linux64_10204.bin: error while loading shared libraries: libclntsh.so.10.1: cannot open shared object file: No such file or directory
解决办法:
1.先检查libclntsh.so.10.1文件是否存在,一般安装完数据库,该文件都会存在。
2.设置oracle的环境变量,加载oracle的lib包export LD_LIBRARY_PATH=$ORACLE_HOME/bin:/bin:/usr/bin:/usr/local/bin:/usr/X11R6/bin/:$ORACLE_HOME/lib:$LD_LIBRARY_PATH
export ORACLE_BASE=/u01/oracle
export ORACLE_HOME=$ORACLE_BASE/product/11.2/db
export ORACLE_SID=oracle
export NLS_DATE_FORMAT="YYYY-MM-DD HH24:MI:SS"
export PATH=.:${PATH}:$HOME/bin:$ORACLE_HOME/bin:$ORACLE_HOME/OPatch
export LD_LIBRARY_PATH=$ORACLE_HOME/bin:/bin:/usr/bin:/usr/local/bin:/usr/X11R6/bin/:$ORACLE_HOME/lib:$LD_LIBRARY_PATH
export CLASSPATH=$ORACLE_HOME/JRE:$ORACLE_HOME/jlib:$ORACLE_HOME/rdbms/jlib
ORA-24345: A Truncation or null fetch error occurred
导出参数加上:safe=yes