<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>TQ 试用 WP &#187; sqlloader</title>
	<atom:link href="http://tq.freehostia.com.freehostia.com/tag/sqlloader/feed" rel="self" type="application/rss+xml" />
	<link>http://tq.freehostia.com.freehostia.com</link>
	<description>TQ 试用中... ...</description>
	<lastBuildDate>Fri, 19 Mar 2010 06:07:08 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>使用sqlloader导入数据</title>
		<link>http://tq.freehostia.com.freehostia.com/2009/09/sqlloader.html</link>
		<comments>http://tq.freehostia.com.freehostia.com/2009/09/sqlloader.html#comments</comments>
		<pubDate>Sat, 26 Sep 2009 07:57:00 +0000</pubDate>
		<dc:creator>TQ</dc:creator>
				<category><![CDATA[Oracle数据库管理]]></category>
		<category><![CDATA[sqlloader]]></category>

		<guid isPermaLink="false">http://tq.freehostia.com.freehostia.com/2009/09/sqlloader.html</guid>
		<description><![CDATA[

今天为开发数据库导入数据，使用sqlloader。记录一下遇到的问题及笔记。  1、表结构如下：
 oss@WINKSDB&#62; desc member_actions; Name              Null?    Type ----------------- -------- ------------ PHONE             NO... ]]></description>
			<content:encoded><![CDATA[<div id="Published By Juziyue-[4]1_124F523B08F540F6AD4293E61293381E_0862E224B1A14E30B1F5C72BD1E6A719_1"></div>
<p><span id="more-192"></span>
<div id="Published By Juziyue-[4]1_124F523B08F540F6AD4293E61293381E_0862E224B1A14E30B1F5C72BD1E6A719">今天为开发数据库导入数据，使用sqlloader。记录一下遇到的问题及笔记。<br/> <br/> <strong>1、表结构如下：</strong>
<pre class="sql"> oss@WINKSDB&gt; desc member_actions; Name              Null?    Type ----------------- -------- ------------ PHONE             NOT NULL VARCHAR2(50) ACTION_TIME       NOT NULL DATE URL                        VARCHAR2(80) APP                        VARCHAR2(20) ACTIVE_LEVEL               VARCHAR2(10) </pre>
<p> <strong>2、要导入的文件（infile），是由log分析得来：</strong><br />
<blockquote>[oracle@devdb: ~]$ll -th deactive_actionlist.2009-09-23-rw-r&#8211;r&#8211; 1 oracle oinstall 49M Sep 24 03:11 deactive_actionlist.2009-09-23[oracle@devdb: ~]$head !$head deactive_actionlist.2009-09-23<font face="宋体" color="#FF00FF" size="2">2009-09-23 00:00:04<strong>,314</strong></font> 13560338333 user/registeruser comm deactive2009-09-23 00:00:17,053 13563963585 user/registeruser comm deactive2009-09-23 00:02:05,704 13810843712 user/registeruser comm deactive2009-09-23 00:02:41,097 13609331107 user/registeruser comm deactive2009-09-23 00:02:43,330 13520106592 user/registeruser comm deactive2009-09-23 00:04:18,818 18702967004 user/registeruser comm deactive2009-09-23 00:05:52,878 15106936277 user/registeruser comm deactive2009-09-23 00:09:14,438 13483699551 user/registeruser comm deactive2009-09-23 00:09:37,988 15910669392 user/registeruser comm deactive2009-09-23 00:09:46,555 15819008127 user/registeruser comm deactive</p></blockquote>
<p> <strong>3、sqlloader的controlfile如下：</strong><br />
<blockquote>
<pre class="sql"> load data                                            --控制文件标识 infile 'deactive_actionlist.2009-09-23'        --要导入数据的文件名 truncate into table MEMBER_ACTIONS                  --truncate table MEMBER_ACTIONS_IMP后，再导入数据 fields terminated by &quot; &quot; optionally enclosed by '&quot;'        --字符终止于“空格”，并附上&quot;双引号(ACTION_TIME POSITION(1:19) date &quot;YYYY-MM-DD HH24:MI:SS&quot;,     --infile中的日期／时间精确到千分秒，而ACTION_TIME列 为DATE型field2 FILLER,                                               --所以多了一段3位的千分秒，要把它漏过去phone, url,app,active_level)                                                       --定义列对应顺序 </pre>
</blockquote>
<blockquote><p><strong>说明：</strong>INSERT：为缺省方式，在数据装载开始时要求表为空。APPEND：在表中追加新记录。REPLACE：使用一种传统DELETE语句；因此，如果要加载的表中已经包含许多记录，这个操作可能执行得很慢。TRUNCATE：则不同，它使用TRUNCATE SQL命令，通常会更快地执行，因为它不必物理地删除每一行。</p></blockquote>
<p> <strong>4、现在来导入并看一下产生的log：</strong><br />
<blockquote>[oracle@devdb: ~]$sqlldr oss/oss control=deactive.ctl <font face="宋体" color="#FF0000" size="2">direct=true</font> &#8212;导入性能果然很快！<font face="宋体" color="#FF0000" size="2">只用了5.75秒</font>。[oracle@devdb: ~]$cat deactive.logSQL*Loader: Release 11.1.0.7.0 &#8211; Production on Fri Sep 25 11:02:59 2009Copyright (c) 1982, 2007, Oracle. All rights reserved.Control File: deactive.ctlData File: deactive_actionlist.2009-09-23 Bad File: deactive_actionlist.bad Discard File: none specified (Allow all discards)Number to load: ALLNumber to skip: 0Errors allowed: 50Continuation: none specifiedPath used: DirectTable MEMBER_ACTIONS, loaded from every logical record.Insert option in effect for this table: TRUNCATE Column Name Position Len Term Encl Datatype&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212; &#8212;&#8212;&#8212;- &#8212;&#8211; &#8212;- &#8212;- &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;ACTION_TIME 1:19 19 WHT O(&quot;) DATE YYYY-MM-DD HH24:MI:SSFIELD2 NEXT * WHT O(&quot;) CHARACTER (FILLER FIELD)PHONE NEXT * WHT O(&quot;) CHARACTER URL NEXT * WHT O(&quot;) CHARACTER APP NEXT * WHT O(&quot;) CHARACTER ACTIVE_LEVEL NEXT * WHT O(&quot;) CHARACTER Table MEMBER_ACTIONS: <font face="宋体" color="#FF0000" size="2">821263 Rows successfully loaded.</font> 0 Rows not loaded due to data errors. 0 Rows not loaded because all WHEN clauses were failed. 0 Rows not loaded because all fields were null. Date conversion cache disabled due to overflow (default size: 1000)Bind array size not used in direct path.Column array rows : 5000Stream buffer bytes: 256000Read buffer bytes: 1048576Total logical records skipped: 0Total logical records read: 821263Total logical records rejected: 0Total logical records discarded: 0Total stream buffers loaded by SQL*Loader main thread: 195Total stream buffers loaded by SQL*Loader load thread: 0Run began on Fri Sep 25 11:02:59 2009Run ended on Fri Sep 25 11:03:05 2009Elapsed time was: <font face="宋体" color="#FF0000" size="2">00:00:05.75</font>CPU time was: 00:00:03.26</p></blockquote>
<p> <strong>5、最后，看看导入的数据有没有问题：</strong>
<pre class="sql"> oss@WINKSDB&gt; select count(*) from member_actions;  COUNT(*)----------    821263oss@WINKSDB&gt; alter session set nls_date_format='yyyy-dd-mm hh24:mi:ss';Session altered.oss@WINKSDB&gt; col phone for a15oss@WINKSDB&gt; col url for a30oss@WINKSDB&gt; col app for a15oss@WINKSDB&gt; select * from member_actions where rownum &lt;= 10;PHONE           ACTION_TIME         URL                            APP             ACTIVE_LEVEL--------------- ------------------- ------------------------------ --------------- ---------------15850680739     2009-23-09 23:21:16 specialwinks                   comm            deactive15819468114     2009-23-09 23:21:16 winks/show                     comm            deactive15817936605     2009-23-09 23:21:16 winks/show                     comm            deactive13471875440     2009-23-09 23:21:16 message                        comm            deactive13262699996     2009-23-09 23:21:16 winks/show                     comm            deactive15129159347     2009-23-09 23:21:16 specialwinks                   comm            deactive13960018854     2009-23-09 23:21:16 specialwinks                   comm            deactive15860758584     2009-23-09 23:21:16 winks/show                     comm            deactive13880176827     2009-23-09 23:21:16 specialwinks                   comm            deactive15120901746     2009-23-09 23:21:16 config                         comm            deactive10 rows selected. </pre>
<p> 导入的数据没有问题！<br/> 该服务器的CPU为1颗4核的Intel(R) Xeon(R) CPU E5410 @ 2.33GHz &nbsp;&nbsp;&nbsp;&nbsp;内存：4G<br/> <br/> &#8211; The End -</div>
]]></content:encoded>
			<wfw:commentRss>http://tq.freehostia.com.freehostia.com/2009/09/sqlloader.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
