简介:oracle数据导出工具sqluldr2可以将数据以csv、txt等格式导出,适用于大批量数据的导出,导出速度非常快。导出后可以使用oracle loader工具将数据导入。

安装:下载:http://www.onexsoft.com/software/sqluldr2linux64.zip
解压zip包,复制sqluldr2_linux64_10204.bin到$ORACLE_HOME的bin目录,重命名为sqluldr2
增加环境变量export LD_LIBRARY_PATH=$ORACLE_HOME/bin:$ORACLE_HOME/lib:/lib:/usr/lib
执行source .bash_profile 应用环境变量。

使用:sqluldr2 --help查看帮助
参数如下:
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)
query参数如果整表导出,可以直接写表名,如果需要查询运算和where条件,query=“sql文本”,也可以把复杂sql写入到文本中由query调用

导出测试:
本地执行方式:users参数可以省略不写,和expdp username/passwd 方式一样
export ORACLE_SID=orcl
sqluldr2 testuser/testuser query=test_table1 file=test_table1.txt
客户端连接:tns方式
sqluldr2 testuser/testuser@orcl query=test_table1 file=test_table1.txt
客户端连接:简易连接
sqluldr2 testuser/[email protected]:1521/orcl query=test_table1 file=test_table1.txt
get_tables.sql为预定义导出sql
sqluldr2 USER=userid/keyword@db_name sql=get_tables.sql head=no FILE=/tmp/stock.csv
对于大表可以输出到多个文件中,指定行数分割或者按照文件大小分割,例如:
sqluldr2 testuser/testuser@orcl query="select * from test_table2" file=testtable2%B.txt batch=yes rows=500000