TOMSYAN 发表于 2011-12-22 08:54

sqlldr交叉导入列值

<DIV>
<DIV><FONT face=宋体 size=2>同事的需求,描述的比较别扭,大体意思如下:</FONT></DIV></DIV>
<DIV><BR><FONT face=宋体 size=2>SQL&gt; DESC TEST;<BR>&nbsp;名称&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 是否为空? 类型<BR>&nbsp;----------------------------------------- -------- ----------------------------</FONT></DIV>
<DIV><FONT face=宋体 size=2>&nbsp;ID&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; CHAR(1)<BR>&nbsp;COL1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; VARCHAR2(4)<BR>&nbsp;COL2&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; VARCHAR2(4)</FONT></DIV>
<DIV><FONT face=宋体 size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=宋体 size=2>ID,COL1,COL2</FONT></DIV>
<DIV>
<DIV><FONT face=宋体 size=2>1,A,1<BR>2,B,2<BR>3,C,3<BR>4,D,4<BR>5,F,5</FONT></DIV>
<DIV><FONT face=宋体 size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=宋体 size=2>数据文件中的这3个列的值对应表的列。</FONT></DIV>
<DIV><FONT face=宋体 size=2>当ID=5的时候, 第一列导入ID,第二列导入COL1,第三列导入COL2</FONT></DIV>
<DIV>
<DIV><FONT face=宋体 size=2>当ID&lt;&gt;5的时候,第一列导入ID,第二列导入COL2,第三列导入COL1</FONT></DIV>
<DIV><FONT face=宋体 size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=宋体 size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=宋体 size=2></FONT>&nbsp;</DIV></DIV></DIV>
<DIV><FONT face=宋体 size=2>实现如下:</FONT></DIV>
<DIV><FONT face=宋体 size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=宋体 size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=宋体 size=2>SQL&gt; HOST TYPE DATA.CTL<BR>LOAD DATA<BR>INFILE 'c:\data.txt'</FONT></DIV>
<DIV><FONT face=宋体 size=2></FONT>&nbsp;</DIV>
<DIV><BR><FONT face=宋体 size=2>APPEND INTO TABLE TEST<BR>WHEN ID='5'<BR>FIELDS TERMINATED BY ','<BR>OPTIONALLY ENCLOSED BY '"'<BR>TRAILING NULLCOLS<BR>(ID ,COL1,COL2)</FONT></DIV>
<DIV><BR><FONT face=宋体 size=2>INTO TABLE TEST<BR>WHEN ID&lt;&gt;'5'<BR>FIELDS TERMINATED BY ','<BR>OPTIONALLY ENCLOSED BY '"'<BR>TRAILING NULLCOLS<BR>(ID <STRONG>POSITION(1),</STRONG>COL2,COL1) --这个地方必须带上POSITION(1),否则只能导入到第一个表中</FONT></DIV>
<DIV><FONT face=宋体 size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=宋体 size=2>SQL&gt; HOST TYPE DATA.TXT<BR>1,A,1<BR>2,B,2<BR>3,C,3<BR>4,D,4<BR>5,F,5</FONT></DIV>
<DIV><BR><FONT face=宋体 size=2>SQL&gt; host sqlldr test/test control=c:\data.ctl</FONT></DIV>
<DIV><FONT face=宋体 size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=宋体 size=2>SQL*Loader: Release 10.2.0.1.0 - Production on 星期二 8月 23 16:30:36 2011</FONT></DIV>
<DIV><FONT face=宋体 size=2>Copyright (c) 1982, 2005, Oracle.&nbsp; All rights reserved.</FONT></DIV>
<DIV><FONT face=宋体 size=2>达到提交点 - 逻辑记录计数 4<BR>达到提交点 - 逻辑记录计数 5</FONT></DIV>
<DIV><FONT face=宋体 size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=宋体 size=2>SQL&gt; SELECT * FROM TEST;</FONT></DIV>
<DIV><FONT face=宋体 size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=宋体 size=2>I COL1 COL2<BR>- ---- ----<BR>1 1&nbsp;&nbsp;&nbsp; A<BR>2 2&nbsp;&nbsp;&nbsp; B<BR>3 3&nbsp;&nbsp;&nbsp; C<BR>4 4&nbsp;&nbsp;&nbsp; D<BR>5 F&nbsp;&nbsp;&nbsp; 5</FONT></DIV>
<DIV><FONT face=宋体 size=2>SQL&gt;</FONT></DIV>
<DIV><FONT face=宋体 size=2></FONT></DIV>
<DIV></DIV>
<DIV></DIV>
页: [1]
查看完整版本: sqlldr交叉导入列值