阿里云-云小站(无限量代金券发放中)
【腾讯云】云服务器、云数据库、COS、CDN、短信等热卖云产品特惠抢购

Oracle利用sqluldr2导出数据

107次阅读
没有评论

共计 3241 个字符,预计需要花费 9 分钟才能阅读完成。

sqluldr2 是一个 基于 OCI 的 文本导出工具,小巧方便,使用方法类似于 Oracle 自带的 exp,支持自定义 SQL、本地和客户端的导出,速度快,效率高。

下载地址,最下面有个小工具里面就有

  1. http://www.onexsoft.com/download.html

也可以直接在系统上 wget

  1. wget http://www.onexsoft.com/software/sqluldr2linux64.zip

解压之后就是一个 bin 文件

  1. -rwxrwxrwx 1 oracle oinstall 185894 1 月 27 2016 sqluldr2linux64.bin

直接执行就能显示帮助

  1. [oracle@hecomoracleserver2 sqluldr2]$ ./sqluldr2linux64.bin
  2. SQL*UnLoader: Fast Oracle Text Unloader (GZIP, Parallel), Release 4.0.1
  3. (@) Copyright Lou Fangxin (AnySQL.net) 2004 – 2010, all rights reserved.
  4. License: Free for non-commercial useage, else 100 USD per server.
  5. Usage: SQLULDR2 keyword=value [,keyword=value,...]
  6. Valid Keywords:
  7.    user = username/password@tnsname
  8.    sql = SQL file name
  9.    query = select statement
  10.    field = separator string between fields
  11.    record = separator string between records
  12.    rows = print progress for every given rows (default, 1000000)
  13.    file = output file name(default: uldrdata.txt)
  14.    log = log file name, prefix with + to append mode
  15.    fast = auto tuning the session level parameters(YES)
  16.    text = output type (MYSQL, CSV, MYSQLINS, ORACLEINS, FORM, SEARCH).
  17.    charset = character set name of the target database.
  18.    ncharset= national character set name of the target database.
  19.    parfile = read command option from parameter file
  20.   for field and record, you can use ‘0x’ to specify hex character code,
  21.   \r=0x0d \n=0x0a |=0x7c ,=0x2c, \t=0x09, :=0x3a, #=0x23, =0x22

上面的参数中,比较常用的是:
   
    query:用这个参数可以自定义导出语句
    file:导出的文件名字和目录
    log:日志
    parfile:可以把参数放到 parfile 文件里,这个参数对于复杂 sql 很有用。
    field: 设置导出文件里的分隔符

连接数据的方法:

        本地连接方式:

  1. ./sqluldr2linux64.bin user=gltest/gltest query=select * from T_H_BK_CUSTOMER_20180114_0; file=/home/oracle/sqluldr2/T_H_BK_CUSTOMER_20180114_0.csv

       客户端连接:TNS 方式

  1. ./sqluldr2linux64.bin user=gltest/gltest@orcl query=select * from T_H_BK_CUSTOMER_20180114_0; file=/home/oracle/sqluldr2/T_H_BK_CUSTOMER_20180114_0.csv

      客户端连接:直接连接方式

  1. ./sqluldr2linux64.bin user=gltest/gltest@192.168.128.98:1521/orcl query=select * from T_H_BK_CUSTOMER_20180114_0; file=/home/oracle/sqluldr2/T_H_BK_CUSTOMER_20180114_0.csv

测试导出速度:

        因为我的 sql 比较长,所以用了 parfile:

  1. [oracle@gloracleserver2 sqluldr2]$ more customer.txt
  2. user=gltest/gltest
  3. query=select ent_code,code,name,cust_levels,dept_code,poi_id,status,createon,createby,lastupdateon from v30_md_customer;

       看看导出输出,1100 万数据不到 30 秒,速度很快。

  1. [oracle@gloracleserver2 sqluldr2]$ ./sqluldr2linux64.bin parfile=/home/oracle/sqluldr2/customer.txt file=/home/oracle/sqluldr2/customer.csv
  2.            0 rows exported at 2018-01-16 20:25:09, size 0 MB.
  3.      1000000 rows exported at 2018-01-16 20:25:11, size 96 MB.
  4.      2000000 rows exported at 2018-01-16 20:25:14, size 196 MB.
  5.      3000000 rows exported at 2018-01-16 20:25:16, size 296 MB.
  6.      4000000 rows exported at 2018-01-16 20:25:18, size 392 MB.
  7.      5000000 rows exported at 2018-01-16 20:25:21, size 492 MB.
  8.      6000000 rows exported at 2018-01-16 20:25:23, size 592 MB.
  9.      7000000 rows exported at 2018-01-16 20:25:26, size 692 MB.
  10.      8000000 rows exported at 2018-01-16 20:25:28, size 788 MB.
  11.      9000000 rows exported at 2018-01-16 20:25:31, size 888 MB.
  12.     10000000 rows exported at 2018-01-16 20:25:34, size 988 MB.
  13.     11000000 rows exported at 2018-01-16 20:25:36, size 1088 MB.
  14.     11317061 rows exported at 2018-01-16 20:25:37, size 1121 MB.
  15.          output file /home/oracle/sqluldr2/customer.csv closed at 11317061 rows, size 1121 MB.

遇到的错误:

        1. 导出文件里有中文显示乱码,需要设置参数 charset=UTF8

        2. ORA-24345: A Truncation or null fetch error occurred,设置参数 safe=yes

更多 Oracle 相关信息见Oracle 专题页面 http://www.linuxidc.com/topicnews.aspx?tid=12

本文永久更新链接地址:http://www.linuxidc.com/Linux/2018-01/150388.htm

正文完
星哥说事-微信公众号
post-qrcode
 0
星锅
版权声明:本站原创文章,由 星锅 于2022-01-22发表,共计3241字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
【腾讯云】推广者专属福利,新客户无门槛领取总价值高达2860元代金券,每种代金券限量500张,先到先得。
阿里云-最新活动爆款每日限量供应
评论(没有评论)
验证码
【腾讯云】云服务器、云数据库、COS、CDN、短信等云产品特惠热卖中