[转载]---Oracle SQL Loader
一、SQL Loader的特点:
Oracle自己带了很多的工具可以用来进行数据的迁移、备份和恢复等工作。但是每个工具都有自己的特点。
比如说exp和imp可以对数据库中的数据进行导出和导入的工作,是一种很好的数据库备份和恢复的工具,因此主要用在数据库的热备份和恢复方面。有着速度快,使用简单,快捷的优点;同时也有一些缺点,比如在不同版本数据库之间的导出、导入的过程之中,总会出现这样或者那样的问题,这个也许是oracle公司自己产品的兼容性的问题。
sql*loader工具却没有这方面的问题。它可以把一些以文本格式存放的数据顺利的导入到oracle数据库中,是一种在不同数据库之间进行数据迁移的非常方便而且通用的工具。缺点就速度比较慢,另外对blob等类型的数据就有点麻烦了。
二、sqlldr帮助:
1 [oracle@yft loader]$ sqlldr 2 3 SQL*Loader: Release 11.2.0.1.0 - Production on Tue Feb 19 11:47:23 2013 4 5 Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved. 6 7 8 Usage: SQLLDR keyword=value [,keyword=value,...] 9 10 Valid Keywords: 11 12 userid -- ORACLE username/password(Oracle用户名/口令) 13 control -- control file name(控制文件名) 14 log -- log file name(日志文件名) 15 bad -- bad file name(错误文件名) 16 data -- data file name(数据文件名) 17 discard -- discard file name(废弃文件名) 18 discardmax -- number of discards to allow(允许废弃的文件的数目) (Default all) 19 skip -- number of logical records to skip(要跳过的逻辑记录的数目) (Default 0) 20 load -- number of logical records to load(要加载的逻辑记录的数目) (Default all) 21 errors -- number of errors to allow(允许的错误的数目) (Default 50) 22 rows -- number of rows in conventional path bind array or between direct path data saves(常规路径绑定数组中或直接路径保存数据间的行数) 23 (Default: Conventional path 64, Direct path all) 24 bindsize -- size of conventional path bind array in bytes(常规路径绑定数组的大小) (Default 256000) 25 silent -- suppress messages during run(运行过程中隐藏消息) (header,feedback,errors,discards,partitions) 26 direct -- use direct path(使用直接路径) (Default FALSE) 27 parfile -- parameter file: name of file that contains parameter specifications(参数文件:包含参数说明的文件的名称) 28 parallel -- do parallel load(执行并行加载) (Default FALSE) 29 file -- file to allocate extents from(要从以下对象中分配区的文件) 30 skip_unusable_indexes -- disallow/allow unusable indexes or index partitions(不允许/允许使用无用的索引或索引分区) (Default FALSE) 31 skip_index_maintenance -- do not maintain indexes, mark affected indexes as unusable(没有维护索引,将受到影响的索引标记为无用) (Default FALSE) 32 commit_discontinued -- commit loaded rows when load is discontinued(提交加载中断时已加载的行) (Default FALSE) 33 readsize -- size of read buffer(读取缓冲区的大小) (Default 1048576) 34 external_table -- use external table for load;(使用外部表进行加载) NOT_USED, GENERATE_ONLY, EXECUTE (Default NOT_USED) 35 columnarrayrows -- number of rows for direct path column array(直接路径列数组的行数) (Default 5000) 36 streamsize -- size of direct path stream buffer in bytes(直接路径流缓冲区的大小) (Default 256000) 37 multithreading -- use multithreading in direct path(在直接路径中使用多线程) 38 resumable -- enable or disable resumable for current session(启用或禁用当前的可恢复会话) (Default FALSE) 39 resumable_name -- text string to help identify resumable statement(有助于标识可恢复语句的文本字符串) 40 resumable_timeout -- wait time (in seconds) for RESUMABLE(RESUMABLE的等待时间) (Default 7200) 41 date_cache -- size (in entries) of date conversion cache(日期转换高速缓存的大小) (Default 1000) 42 no_index_errors -- abort load on any index errors (Default FALSE) 43 44 PLEASE NOTE: Command-line parameters may be specified either by 45 position or by keywords. An example of the former case is 'sqlldr 46 scott/tiger foo'; an example of the latter is 'sqlldr control=foo 47 userid=scott/tiger'. One may specify parameters by position before 48 but not after parameters specified by keywords. For example, 49 'sqlldr scott/tiger control=foo logfile=log' is allowed, but 50 'sqlldr scott/tiger control=foo log' is not, even though the 51 position of the parameter 'log' is correct.
三、SQL LOADER实例:
----创建一个张测试表----
1 SQL> show user 2 USER is "JACK" 3 4 SQL> create table jack (id int,name varchar2(10)); 5 6 Table created. 7 ----控制文件内容----
8 [oracle@yft loader]$ cat input.ctl 9 load data 10 infile '/home/oracle/loader/jack.txt' 11 append into table jack 12 (id char terminated by ',', 13 name char terminated by whitespace) 14 ----数据文件内容----
15 [oracle@yft loader]$ cat jack.txt 16 1,aa 17 2,bb 18 3,cc 19 ----执行sqlldr命令,数据加载----
20 [oracle@yft loader]$ sqlldr userid=jack/jack control=input.ctl 21 22 SQL*Loader: Release 11.2.0.1.0 - Production on Tue Feb 19 12:48:29 2013 23 24 Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved. 25 26 Commit point reached - logical record count 3 27 28 ----查看日志文件中有没有报错----
29 [oracle@yft loader]$ cat input.log 30 31 SQL*Loader: Release 11.2.0.1.0 - Production on Tue Feb 19 12:48:29 2013 32 33 Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved. 34 35 Control File: input.ctl 36 Data File: /home/oracle/loader/jack.txt 37 Bad File: jack.bad 38 Discard File: none specified 39 40 (Allow all discards) 41 42 Number to load: ALL 43 Number to skip: 0 44 Errors allowed: 50 45 Bind array: 64 rows, maximum of 256000 bytes 46 Continuation: none specified 47 Path used: Conventional 48 49 Table JACK, loaded from every logical record. 50 Insert option in effect for this table: APPEND 51 52 Column Name Position Len Term Encl Datatype 53 ------------------------------ ---------- ----- ---- ---- --------------------- 54 ID FIRST * , CHARACTER 55 NAME NEXT * WHT CHARACTER 56 57 58 Table JACK: 59 3 Rows successfully loaded. 60 0 Rows not loaded due to data errors. 61 0 Rows not loaded because all WHEN clauses were failed. 62 0 Rows not loaded because all fields were null. 63 64 65 Space allocated for bind array: 33024 bytes(64 rows) 66 Read buffer bytes: 1048576 67 68 Total logical records skipped: 0 69 Total logical records read: 3 70 Total logical records rejected: 0 71 Total logical records discarded: 0 72 73 Run began on Tue Feb 19 12:48:29 2013 74 Run ended on Tue Feb 19 12:48:30 2013 75 76 Elapsed time was: 00:00:00.13 77 CPU time was: 00:00:00.03 78 ----验证数据是否已经加载进去----
79 SQL> select * from jack; 80 81 ID NAME 82 ---------- ---------- 83 1 aa 84 2 bb 85 3 cc