ºìÁªLinuxÃÅ»§
Linux°ïÖú

Oracle&MysqlÊý¾Ýµ¼Èë·½·¨

·¢²¼Ê±¼ä:2006-10-17 22:46:25À´Ô´:ºìÁª×÷Õß:linuxcms
MysqlÊý¾Ýµ¼Èë·½·¨:
»ù±¾Óï·¨:
LOAD DATA INFILE [Load_file]
INTO TABLE [DestTable]
FIELDS TERMINATED BY '\t'
LINES TERMINATED BY '\n';

[Load_file] Òªµ¼ÈëÄ¿±ê±íµÄÎı¾Îļþ,ÎļþÃû³ÆÈÎÒâ,µ«ÊǸÃÎļþµÄ¸ñʽҪÓëµ¼ÈëµÄÄ¿µÄ±íµÄ¸ñʽÍêÈ«Ò»ÖÂ,·ñÔòµ¼Èëʱ¿ÉÄÜ·¢Éúµ¼Èëʧ°Ü»òÕßµ¼Èë´íÐеÄÇé¿ö³öÏÖ.ÁíÍâ,µ¼ÈëµÄÎļþÒ»¶¨ÒªÔÚMysqlËùÔڵķþÎñÆ÷´ÅÅÌÏÂ(·ÖÇøÈÎÒâ).
[DestTable] Òªµ¼ÈëÄ¿±ê±í
FIELDS TERMINATED BY '\t' ×ֶηָô±êÖ¾,Èç¹û¸Ã×Ö¶ÎÊýֵΪ¿Õ,ÔòÖ»ÊäÈë\t
LINES TERMINATED BY '\n' ¼Ç¼·Ö¸ô±êÖ¾£¬Í¨³£Îª\n»»ÐÐ

PerlÖпÉÖ±½ÓÓÃDBIµÄdo/prepare executeÖ´ÐУ¬µ«ÊÇÒ»¶¨ÒªÈ·±£Òªµ¼ÈëµÄÎļþÔÚMysql·þÎñÆ÷ÉÏ¡£

OracleÊý¾Ýµ¼Èë·½·¨£º
Êý¾Ýµ¼ÈëÒ»°ãÐèÒªÁ½¸öÎļþ.ctlÎļþºÍ.unlÎļþ¡£
ctlÎļþ´æ·ÅµÄΪÐèÒªµ¼ÈëµÄ×Ö¶ÎÐÅÏ¢,×Ö¶ÎÖ®¼ä·Ö¸ô·ûºÅµÈ
unlÎļþ´æ·ÅÐèÒªµ¼Èë±íµÄÊý¾Ý

¼ÙÉèÓбítest_table
create test_table
(
a varchar(255),
b varchar(255)
)
1¡¢½¨Á¢test.ctl
--test.ctl
load data¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡
infile 'c:\test.unl'
--×¢ÒâÕâÀïµÄ·¾¶¸Ä³ÉÊý¾ÝÎļþµÄ·¾¶,Èç¹ûÊǵ±Ç°Ä¿Â¼Ï¿ÉÒÔ²»Ð´Â·¾¶
append into table test_table
fields terminated by '|'
trailing nullcols ¡¡¡¡
(
A ,
B
--ÉÏÃæÕâЩ×Ö¶ÎÊÇʵ¼ÊÊý¾Ý¿âÖÐtest.unl±íµÄ×Ö¶Î
)

2¡¢½¨Á¢test.unl
aaa|bbb

3¡¢µ¼ÈëÊý¾Ý£º
ÔÚwindowsµÄcmdģʽÏÂ×ö:
sqlldr npmdb/npmoptr@tjnpm control=%·¾¶%\test.ctl
--×¢ÒâÕâÀïµÄ·¾¶¸Ä³ÉÊý¾ÝÎļþµÄ·¾¶,Èç¹ûÊǵ±Ç°Ä¿Â¼Ï¿ÉÒÔ²»Ð´Â·¾¶
ÎÄÕÂÆÀÂÛ

¹²ÓÐ 0 ÌõÆÀÂÛ