﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>语源科技BlogJava-花木</title><link>http://www.blogjava.net/w19995/</link><description /><language>zh-cn</language><lastBuildDate>Thu, 07 May 2026 00:59:54 GMT</lastBuildDate><pubDate>Thu, 07 May 2026 00:59:54 GMT</pubDate><ttl>60</ttl><item><title>学习oracle sql loader 的使用【转】</title><link>http://www.blogjava.net/w19995/archive/2005/11/16/20030.html</link><dc:creator>花木</dc:creator><author>花木</author><pubDate>Wed, 16 Nov 2005 04:05:00 GMT</pubDate><guid>http://www.blogjava.net/w19995/archive/2005/11/16/20030.html</guid><wfw:comment>http://www.blogjava.net/w19995/comments/20030.html</wfw:comment><comments>http://www.blogjava.net/w19995/archive/2005/11/16/20030.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/w19995/comments/commentRss/20030.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/w19995/services/trackbacks/20030.html</trackback:ping><description><![CDATA[<P>学习oracle sql loader 的使用</P>
<P>一：sql loader 的特点<BR>oracle自己带了很多的工具可以用来进行数据的迁移、备份和恢复等工作。但是每个工具都有自己的特点。<BR>&nbsp;比如说exp和imp可以对数据库中的数据进行导出和导出的工作，是一种很好的数据库备份和恢复的工具，因此主要用在数据库的热备份和恢复方面。有着速度快，使用简单，快捷的优点；同时也有一些缺点，比如在不同版本数据库之间的导出、导入的过程之中，总会出现这样或者那样的问题，这个也许是oracle公司自己产品的兼容性的问题吧。<BR>&nbsp;sql loader 工具却没有这方面的问题，它可以把一些以文本格式存放的数据顺利的导入到oracle数据库中，是一种在不同数据库之间进行数据迁移的非常方便而且通用的工具。缺点就速度比较慢，另外对blob等类型的数据就有点麻烦了。<BR>&nbsp;<BR>二：sql loader 的帮助</P>
<P>C:\&gt;sqlldr</P>
<P>SQL*Loader: Release 9.2.0.1.0 - Production on 星期六 10月 9 14:48:12 2004</P>
<P>Copyright (c) 1982, 2002, Oracle Corporation.&nbsp; All rights reserved.</P>
<P><BR>用法: SQLLDR keyword=value [,keyword=value,...]</P>
<P>有效的关键字:</P>
<P>&nbsp;&nbsp;&nbsp; userid -- ORACLE username/password<BR>&nbsp;&nbsp; control -- Control file name<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; log -- Log file name<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; bad -- Bad file name<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; data -- Data file name<BR>&nbsp;&nbsp; discard -- Discard file name<BR>discardmax -- Number of discards to allow&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (全部默认)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; skip -- Number of logical records to skip&nbsp; (默认0)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; load -- Number of logical records to load&nbsp; (全部默认)<BR>&nbsp;&nbsp;&nbsp; errors -- Number of errors to allow&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (默认50)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; rows -- Number of rows in conventional path bind array or between direct p<BR>ath data saves<BR>（默认: 常规路径 64, 所有直接路径）<BR>&nbsp; bindsize -- Size of conventional path bind array in bytes(默认256000)<BR>&nbsp;&nbsp;&nbsp; silent -- Suppress messages during run (header,feedback,errors,discards,part<BR>itions)<BR>&nbsp;&nbsp;&nbsp; direct -- use direct path&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (默认FALSE)<BR>&nbsp;&nbsp; parfile -- parameter file: name of file that contains parameter specification<BR>s<BR>&nbsp; parallel -- do parallel load&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (默认FALSE)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; file -- File to allocate extents from<BR>skip_unusable_indexes -- disallow/allow unusable indexes or index partitions(默<BR>认FALSE)<BR>skip_index_maintenance -- do not maintain indexes, mark affected indexes as unus<BR>able(默认FALSE)<BR>&nbsp; readsize -- Size of Read buffer&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (默认1048576)<BR>external_table -- use external table for load; NOT_USED, GENERATE_ONLY, EXECUTE(<BR>默认NOT_USED)<BR>columnarrayrows -- Number of rows for direct path column array(默认5000)<BR>streamsize -- Size of direct path stream buffer in bytes(默认256000)<BR>multithreading -- use multithreading in direct path<BR>&nbsp;resumable -- enable or disable resumable for current session(默认FALSE)<BR>resumable_name -- text string to help identify resumable statement<BR>resumable_timeout -- wait time (in seconds) for RESUMABLE(默认7200)<BR>date_cache -- size (in entries) of date conversion cache(默认1000)</P>
<P>PLEASE NOTE: 命令行参数可以由位置或关键字指定<BR>。前者的例子是 'sqlload<BR>scott/tiger foo'; 后一种情况的一个示例是 'sqlldr control=foo<BR>userid=scott/tiger'.位置指定参数的时间必须早于<BR>但不可迟于由关键字指定的参数。例如,<BR>允许 'sqlldr scott/tiger control=foo logfile=log', 但是<BR>不允许 'sqlldr scott/tiger control=foo log', 即使<BR>参数 'log' 的位置正确。</P>
<P>C:\&gt;</P>
<P>三：sql loader使用例子<BR>a）SQLLoader将 Excel 数据导出到 Oracle<BR>1.创建SQL*Loader输入数据所需要的文件,均保存到C:\，用记事本编辑： <BR>控制文件：input.ctl，内容如下： <BR>&nbsp; <BR>　　load data　　　　　　　　　　 --1、控制文件标识 <BR>　　infile 'test.txt'　　　　　　 --2、要输入的数据文件名为test.txt <BR>　　append into table test　　　　--3、向表test中追加记录 <BR>　　fields terminated by X'09'　　--4、字段终止于X'09'，是一个制表符（TAB） <BR>　　(id,username,password,sj)　　 -----定义列对应顺序 <BR>&nbsp; <BR>a、insert，为缺省方式，在数据装载开始时要求表为空 <BR>b、append，在表中追加新记录 <BR>c、replace <BR>，删除旧记录，替换成新装载的记录 <BR>d、truncate，同上 <BR>&nbsp; <BR>在DOS窗口下使用SQL*Loader命令实现数据的输入 <BR>&nbsp; <BR>C:\&gt;sqlldr userid=system/manager control=input.ctl <BR>&nbsp; 默认日志文件名为：input.log <BR>默认坏记录文件为：input.bad <BR>&nbsp; <BR>2.还有一种方法<BR>可以把EXCEL文件另存为CSV（逗号分隔）(*.csv),控制文件就改为用逗号分隔 <BR>LOAD DATA <BR>INFILE 'd:\car.csv' <BR>APPEND&nbsp; INTO TABLE t_car_temp <BR>FIELDS TERMINATED BY "," <BR>(phoneno,vip_car) </P>
<P></P>
<P>b）在控制文件中直接导入数据</P>
<P>1、控制文件test.ctl的内容<BR>-- The format for executing this file with SQL Loader is:<BR>-- SQLLDR control=&lt;filename&gt; Be sure to substitute your<BR>-- version of SQL LOADER and the filename for this file.<BR>LOAD DATA<BR>INFILE *<BR>BADFILE 'C:\Documents and Settings\Jackey\桌面\WMCOUNTRY.BAD'<BR>DISCARDFILE 'C:\Documents and Settings\Jackey\桌面\WMCOUNTRY.DSC'<BR>INSERT INTO TABLE EMCCOUNTRY<BR>Fields terminated by ";" Optionally enclosed by '"'<BR>(<BR>&nbsp; COUNTRYID NULLIF (COUNTRYID="NULL"),<BR>&nbsp; COUNTRYCODE,<BR>&nbsp; COUNTRYNAME,<BR>&nbsp; CONTINENTID NULLIF (CONTINENTID="NULL"),<BR>&nbsp; MAPID NULLIF (MAPID="NULL"),<BR>&nbsp; CREATETIME DATE "MM/DD/YYYY HH24:MI:SS" NULLIF (CREATETIME="NULL"),<BR>&nbsp; LASTMODIFIEDTIME DATE "MM/DD/YYYY HH24:MI:SS" NULLIF (LASTMODIFIEDTIME="NULL")<BR>)<BR>BEGINDATA<BR>1;"JP";"Japan";1;9;"09/16/2004 16:31:32";NULL<BR>2;"CN";"China";1;10;"09/16/2004 16:31:32";NULL<BR>3;"IN";"India";1;11;"09/16/2004 16:31:32";NULL<BR>4;"AU";"Australia";6;12;"09/16/2004 16:31:32";NULL<BR>5;"CA";"Canada";4;13;"09/16/2004 16:31:32";NULL<BR>6;"US";"United States";4;14;"09/16/2004 16:31:32";NULL<BR>7;"MX";"Mexico";4;15;"09/16/2004 16:31:32";NULL<BR>8;"GB";"United Kingdom";3;16;"09/16/2004 16:31:32";NULL<BR>9;"DE";"Germany";3;17;"09/16/2004 16:31:32";NULL<BR>10;"FR";"France";3;18;"09/16/2004 16:31:32";NULL<BR>11;"IT";"Italy";3;19;"09/16/2004 16:31:32";NULL<BR>12;"ES";"Spain";3;20;"09/16/2004 16:31:32";NULL<BR>13;"FI";"Finland";3;21;"09/16/2004 16:31:32";NULL<BR>14;"SE";"Sweden";3;22;"09/16/2004 16:31:32";NULL<BR>15;"IE";"Ireland";3;23;"09/16/2004 16:31:32";NULL<BR>16;"NL";"Netherlands";3;24;"09/16/2004 16:31:32";NULL<BR>17;"DK";"Denmark";3;25;"09/16/2004 16:31:32";NULL<BR>18;"BR";"Brazil";5;85;"09/30/2004 11:25:43";NULL<BR>19;"KR";"Korea, Republic of";1;88;"09/30/2004 11:25:43";NULL<BR>20;"NZ";"New Zealand";6;89;"09/30/2004 11:25:43";NULL<BR>21;"BE";"Belgium";3;79;"09/30/2004 11:25:43";NULL<BR>22;"AT";"Austria";3;78;"09/30/2004 11:25:43";NULL<BR>23;"NO";"Norway";3;82;"09/30/2004 11:25:43";NULL<BR>24;"LU";"Luxembourg";3;81;"09/30/2004 11:25:43";NULL<BR>25;"PT";"Portugal";3;83;"09/30/2004 11:25:43";NULL<BR>26;"GR";"Greece";3;80;"09/30/2004 11:25:43";NULL<BR>27;"IL";"Israel";1;86;"09/30/2004 11:25:43";NULL<BR>28;"CH";"Switzerland";3;84;"09/30/2004 11:25:43";NULL<BR>29;"A1";"Anonymous Proxy";0;0;"09/30/2004 11:25:43";NULL<BR>30;"A2";"Satellite Provider";0;0;"09/30/2004 11:25:43";NULL<BR>31;"AD";"Andorra";3;0;"09/30/2004 11:25:43";NULL<BR>32;"AE";"United Arab Emirates";1;0;"09/30/2004 11:25:43";NULL<BR>33;"AF";"Afghanistan";1;0;"09/30/2004 11:25:43";NULL<BR>34;"AG";"Antigua and Barbuda";7;0;"09/30/2004 11:25:43";NULL<BR>35;"AI";"Anguilla";7;0;"09/30/2004 11:25:43";NULL<BR>36;"AL";"Albania";3;0;"09/30/2004 11:25:43";NULL<BR>37;"AM";"Armenia";3;0;"09/30/2004 11:25:43";NULL<BR>38;"AN";"Netherlands Antilles";3;0;"09/30/2004 11:25:43";NULL<BR>39;"AO";"Angola";2;0;"09/30/2004 11:25:43";NULL<BR>40;"AP";"Asia/Pacific Region";2;0;"09/30/2004 11:25:43";NULL<BR>41;"AQ";"Antarctica";8;0;"09/30/2004 11:25:43";NULL<BR>42;"AR";"Argentina";5;0;"09/30/2004 11:25:43";NULL<BR>43;"AS";"American Samoa";6;0;"09/30/2004 11:25:43";NULL<BR>44;"AW";"Aruba";5;0;"09/30/2004 11:25:43";NULL<BR>45;"AZ";"Azerbaijan";1;0;"09/30/2004 11:25:43";NULL<BR>46;"BA";"Bosnia and Herzegovina";3;0;"09/30/2004 11:25:43";NULL<BR>47;"BB";"Barbados";5;0;"09/30/2004 11:25:43";NULL<BR>48;"BD";"Bangladesh";1;0;"09/30/2004 11:25:43";NULL<BR>49;"BF";"Burkina Faso";2;0;"09/30/2004 11:25:43";NULL<BR>50;"BG";"Bulgaria";3;0;"09/30/2004 11:25:43";NUL<BR>L<BR>51;"BH";"Bahrain";1;0;"09/30/2004 11:25:43";NULL<BR>52;"BI";"Burundi";2;0;"09/30/2004 11:25:43";NULL<BR>53;"BJ";"Benin";2;0;"09/30/2004 11:25:43";NULL<BR>54;"BM";"Bermuda";4;0;"09/30/2004 11:25:43";NULL<BR>55;"BN";"Brunei Darussalam";1;0;"09/30/2004 11:25:43";NULL<BR>56;"BO";"Bolivia";5;0;"09/30/2004 11:25:43";NULL<BR>57;"BS";"Bahamas";7;0;"09/30/2004 11:25:43";NULL<BR>58;"BT";"Bhutan";1;0;"09/30/2004 11:25:43";NULL<BR>59;"BV";"Bouvet Island";5;0;"09/30/2004 11:25:43";NULL<BR>60;"BW";"Botswana";2;0;"09/30/2004 11:25:43";NULL<BR>61;"BY";"Belarus";3;0;"09/30/2004 11:25:43";NULL<BR>2、执行导入命令<BR>C:\&gt;sqlldr userid=system/manager control=test.ctl </P>
<P></P>
<P>c）复杂格式的导入<BR></P></SPAN><img src ="http://www.blogjava.net/w19995/aggbug/20030.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/w19995/" target="_blank">花木</a> 2005-11-16 12:05 <a href="http://www.blogjava.net/w19995/archive/2005/11/16/20030.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>