分别对应32为,64位的win和Linux平台
安装步骤
1.需要安装oracle_client
2.复制sqluldr2_linux32_10204.bin(64位系统用sqluldr2_linux64_10204.bin)到$ORACLE_HOME的bin目录,重命名为sqluldr2.bin
3.修改 $HOME目录下.bash_profile 增加如下环境变量
-bash-3.2$ sqluldr2.bin
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
LINUX下用法:
get_tables.sql为预定义导出sql
-bash-3.2$ sqluldr2.bin USER=userid/keyword@db_name sql=get_tables.sql head=no FILE=/oracle/oradata/backup/stock.csv
0 rows exported at 2014-05-06 11:49:25, size 0 MB.
1000000 rows exported at 2014-05-06 11:49:28, size 24 MB.
2000000 rows exported at 2014-05-06 11:49:32, size 48 MB.
3000000 rows exported at 2014-05-06 11:49:35, size 76 MB.
4000000 rows exported at 2014-05-06 11:49:38, size 100 MB.
5000000 rows exported at 2014-05-06 11:49:41, size 124 MB.
6000000 rows exported at 2014-05-06 11:49:44, size 152 MB.
7000000 rows exported at 2014-05-06 11:49:47, size 176 MB.
8000000 rows exported at 2014-05-06 11:49:50, size 204 MB.
9000000 rows exported at 2014-05-06 11:49:53, size 228 MB.
10000000 rows exported at 2014-05-06 11:49:56, size 252 MB.
11000000 rows exported at 2014-05-06 11:49:59, size 280 MB.
12000000 rows exported at 2014-05-06 11:50:02, size 304 MB.
13000000 rows exported at 2014-05-06 11:50:05, size 328 MB.
14000000 rows exported at 2014-05-06 11:50:08, size 356 MB.
15000000 rows exported at 2014-05-06 11:50:11, size 380 MB.
16000000 rows exported at 2014-05-06 11:50:14, size 408 MB.
17000000 rows exported at 2014-05-06 11:50:17, size 432 MB.
18000000 rows exported at 2014-05-06 11:50:20, size 456 MB.
19000000 rows exported at 2014-05-06 11:50:23, size 484 MB.
20000000 rows exported at 2014-05-06 11:50:27, size 508 MB.
21000000 rows exported at 2014-05-06 11:50:30, size 531 MB.
21877116 rows exported at 2014-05-06 11:50:33, size 558 MB.
output file /oracle/oradata/backup/f_stock.csv closed at 21877116 rows, size 558 MB.
-bash-3.2$
下为WINDOWS平台使用方法:
代码例子1:
sqluldr2.exe USER=用户/密码@tnsQUERY="select /*+ parallel(8) */ *from cs_XXX dt,cfg_XXX devdim105 wheredt.starttime>=to_date('2012-06-27 00:00:00','yyyy-mm-dd hh34:mi:ss') and dt.starttime<=to_date('2012-06-2700:01:59','yyyy-mm-dd hh34:mi:ss') AND dt.msc= devdim105.mapvalue(+) ANDdevdim105.deviceid=15 " head=yes FILE=F:\cs_XXX_test.csv
代码例子2(这种方式用于导出的查询sql很长,那么就把sql写在123.sql文件里 ):
sqluldr2.exe USER=用户/密码@tns sql=123.sql head=yes FILE=F:\cs_XXX_test.csv
3.在cmd里,直接把步骤2的代码例子1 ,贴进去执行。
注:如果执行报报错,就有可能是环境变量path的问题,还有就是plsql需要的oci.dll文件等多个dll文件,请放在sqluldr2的目录下。
4.查看结果F:\cs_XXX_test.csv
5.打开csv里面的内容,就可以用sqlldr进行 入库。
字符集的控制:
默认情况下, Oracle客户端程序的字符集都由环境变量(NLS_LANG)决定, 很多时侯会因为忽略了环境变量的检查, 尤其是在Shell或Perl脚本中调用时, 导致导出的数据变成了乱码. 在OCI 8的接口中, 可以使用OCIEnvNlsCreate函数在程序中指定客户端字符集, 从而跳过环境变量的影响, 于是就在SQLULDR2工具中新增了两个选项, 用于指定导出时了字符集.
新的SQLULDR2工具命令行帮助如下所示:
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 filefor field and record, you can use '0x' to specify hex character code,
\r=0x0d \n=0x0a |=0x7c ,=0x2c, \t=0x09, :=0x3a, #=0x23, "=0x22 '=0x27
在一个GBK的数据库中存入"中国"两个字, 然后以GBK和UTF8两种不同的字符集进行导出, 在命令行指定字符集设置.
C:\>sqluldr2 scott/tiger query=test charset=ZHS16GBK
0 rows exported at 2010-06-24 09:12:27, size 0 MB.
1 rows exported at 2010-06-24 09:12:27, size 0 MB.
output file uldrdata.1.txt closed at 1 rows, size 0 MB.C:\>dir uldrdata.1.txt
2010-06-24 09:12 5 uldrdata.1.txtC:\>sqluldr2 scott/tiger query=test charset=UTF8
0 rows exported at 2010-06-24 09:12:42, size 0 MB.
1 rows exported at 2010-06-24 09:12:42, size 0 MB.
output file uldrdata.1.txt closed at 1 rows, size 0 MB.C:\>dir uldrdata.1.txt
2010-06-24 09:12 7 uldrdata.1.txt
用GBK导出时, 文件大小为5个字节, 两个汉字(一个汉字占两个字节)再加一个换行符. 而用UTF8导出时, 文件大小为7, 两个汉字(一个汉字占三个字节)加上一个换行符. 如果用SQLULDR2为特定的数据库写脚本程序时, 在命令行指定字符集, 将使脚本更加强壮.
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。