oracle导入导出文本利器-sqluldr and sqlldr

oracle导入导出文本利器-sqluldr  and sqlldr

sqlldr 导入工具

sqludr导出工具

 例子:

由于表属于生产环境的表,所以表名和列名隐藏部分

1、导出表

下载sqluldr2_linux64_10204.bin

拷贝到$ORACLE_HOME/bin  命名为sqludr

查看帮助:
[oracle@oracle ~]$ sqluldr


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


导出表数据:这里注意如果有中文字符,记得转换字符集 export NLS_LANG="SIMPLIFIED CHINESE_CHINA.ZHS16GBK"

sqluldr clspuser/oracle query="select column,column1 from table where column=values" field="@|@" record=0x0a file=/u01/sqluldr/tablename.txt   --分隔符为@|@,行结尾为0x0a也就是\n换行。


屏幕显示
           0 rows exported at 2016-04-26 16:00:16, size 0 MB.
        4386 rows exported at 2016-04-26 16:00:16, size 3 MB.
         output file /u01/sqluldr/tablename.txt closed at 4386 rows, size 3 MB.


2.导入到数据库

 查看sqlldr帮助
SQL*Loader: Release 11.2.0.3.0 - Production on Tue Apr 26 16:48:27 2016


Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.




Usage: SQLLDR keyword=value [,keyword=value,...]


Valid Keywords:


    userid -- ORACLE username/password
   control -- control file name
       log -- log file name
       bad -- bad file name
      data -- data file name
   discard -- discard file name
discardmax -- number of discards to allow          (Default all)
      skip -- number of logical records to skip    (Default 0)
      load -- number of logical records to load    (Default all)
    errors -- number of errors to allow            (Default 50)
      rows -- number of rows in conventional path bind array or between direct path data saves
               (Default: Conventional path 64, Direct path all)
  bindsize -- size of conventional path bind array in bytes  (Default 256000)
    silent -- suppress messages during run (header,feedback,errors,discards,partitions)
    direct -- use direct path                      (Default FALSE)
   parfile -- parameter file: name of file that contains parameter specifications
  parallel -- do parallel load                     (Default FALSE)
      file -- file to allocate extents from
skip_unusable_indexes -- disallow/allow unusable indexes or index partitions  (Default FALSE)
skip_index_maintenance -- do not maintain indexes, mark affected indexes as unusable  (Default FALSE)
commit_discontinued -- commit loaded rows when load is discontinued  (Default FALSE)
  readsize -- size of read buffer                  (Default 1048576)
external_table -- use external table for load; NOT_USED, GENERATE_ONLY, EXECUTE  (Default NOT_USED)
columnarrayrows -- number of rows for direct path column array  (Default 5000)
streamsize -- size of direct path stream buffer in bytes  (Default 256000)
multithreading -- use multithreading in direct path
 resumable -- enable or disable resumable for current session  (Default FALSE)
resumable_name -- text string to help identify resumable statement
resumable_timeout -- wait time (in seconds) for RESUMABLE  (Default 7200)
date_cache -- size (in entries) of date conversion cache  (Default 1000)
no_index_errors -- abort load on any index errors  (Default FALSE)


PLEASE NOTE: Command-line parameters may be specified either by
position or by keywords.  An example of the former case is 'sqlldr
scott/tiger foo'; an example of the latter is 'sqlldr control=foo
userid=scott/tiger'.  One may specify parameters by position before
but not after parameters specified by keywords.  For example,
'sqlldr scott/tiger control=foo logfile=log' is allowed, but
'sqlldr scott/tiger control=foo log' is not, even though the
position of the parameter 'log' is correct.


使用sqlldr先书写控制文件

vim tablename.ctl

load data
CHARACTERSET ZHS16GBK
infile '/u01/sqluldr/tablename.txt'
append into table tablename
fields terminated by '@|@'  ---间隔符为@|@
trailing nullcols        ----即使有为空的列,也以null值插入
(column,column2)


执行命令
[oracle@oracle ~]$ sqlldr userid=clspuser/oracle control=/home/oracle/tablename.ctl log=p2p.log

......
Commit point reached - logical record count 4230
Commit point reached - logical record count 4239
Commit point reached - logical record count 4248
Commit point reached - logical record count 4257
Commit point reached - logical record count 4266
Commit point reached - logical record count 4275
Commit point reached - logical record count 4284
Commit point reached - logical record count 4293
Commit point reached - logical record count 4302
Commit point reached - logical record count 4311
Commit point reached - logical record count 4320
Commit point reached - logical record count 4329
Commit point reached - logical record count 4338
Commit point reached - logical record count 4347
Commit point reached - logical record count 4356
Commit point reached - logical record count 4365
Commit point reached - logical record count 4374
Commit point reached - logical record count 4383
Commit point reached - logical record count 4386

插入4386

验证两边的数据是否相同

over


你可能感兴趣的:(oracle导入导出文本利器-sqluldr and sqlldr)