sqluldr2的使用方法

点击查看全文


有时候需要导出Oracle表数据到文本中用来迁移数据、异构平台或大数据的数据处理。导出方法有很多种,例如:spool、plsql-developer、utl_file方法等,除了这些方法,还有一个工具很火就是sqluldr2,老楼开发的工具。现在对这些工具做个对比和总结。
一、数据导出工具概览
1、spool
spool工具在sqlplus中随时可以使用,较为灵活,通过sqlplus的格式设置处理,字段分割利用sql语句拼成,能迅速导出一些小数据量的需求。因为是配合sqlplus,它可以支持本地和客户端的数据导出,但是效率不高。

2、plsql-developer
plsql-developer工具只是个代表,还有很多工具可以连接数据库,进行导出操作,从交互配置中完成需要导出的数据设置。它也可以支持本地和客户端的数据导出,效率高于spool。

3、utl_file方法
utl_file方法是oracle提供的文件读写包,该方法需要一定的编写存储过程和sql的能力,而且需要指定读写路径,因此只能在服务器本地生成文件,若大量导出,还需要完成文件的传输。

4、sqluldr2
老楼开发的软件,基于OCI,使用非常方便,就是一个可执行文件配合参数命令,类似expdp等的命令行使用方法,支持自定义sql、本地和客户端的导出,效率非常高。
前三个方法都能轻松找到使用方法,本次实测sqluldr2。

二、sqluldr2的测试使用
1、获取工具
下载:http://www.onexsoft.com/software/sqluldr2linux64.zip
上传解压即可使用
2、工具的参数
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

3、执行导出
3.1 sqluldr2的链接数据库
本地执行方式: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

3.2 要导出的数据由query控制
query参数如果整表导出,可以直接写表名,如果需要查询运算和where条件,query=“sql文本”,也可以把复杂sql写入到文本中由query调用。

3.3 分隔符设置
默认是逗号分隔符,通过field参数指定分隔符
sqluldr2 testuser/testuser query=chen.tt1 field=";"

3.4 大数据量操作


点击查看全文

sqluldr2的使用方法_第1张图片

你可能感兴趣的:(大数据,阿里云)