一、SQLLoader將 Excel 資料匯出到 Oracle
1.建立SQL*Loader輸入資料所需要的檔案,均儲存到C:\,用記事本編輯:
控制檔案:input.ctl,內容如下:
load data --1、控制檔案標識
infile 'test.txt' --2、要輸入的資料檔案名為test.txt
append into table test --3、向表test中追加記錄
fields terminated by X'09' --4、欄位終止於X'09',是一個定位字元(TAB)
(id,username,password,sj) -----定義列對應順序
a、insert,為預設方式,在資料裝載開始時要求表為空白
b、append,在表中追加新記錄
c、replace,刪除舊記錄,替換成新裝載的記錄
d、truncate,同上
在DOS視窗下使用SQL*Loader命令實現資料的輸入
C:>\sqlldr userid=system/manager control=input.ctl
預設記錄檔名為:input.log
預設壞記錄檔案為:input.bad
2.還有一種方法
可以把EXCEL檔案另存新檔CSV(逗號分隔)(*.csv),控制檔案就改為用逗號分隔
LOAD DATA
INFILE 'd:\car.csv'
APPEND INTO TABLE t_car_temp
FIELDS TERMINATED BY ","
(phoneno,vip_car)
二、在控制檔案中直接匯入資料
1、控制檔案test.ctl的內容
-- The format for executing this file with SQL Loader is:
-- SQLLDR control=<filename> Be sure to substitute your
-- version of SQL LOADER and the filename for this file.
LOAD DATA
INFILE *
BADFILE 'C:\Documents and Settings\Jackey\案頭\WMCOUNTRY.BAD'
DISCARDFILE 'C:\Documents and Settings\Jackey\案頭\WMCOUNTRY.DSC'
INSERT INTO TABLE EMCCOUNTRY
Fields terminated by ";" Optionally enclosed by '"'
(
COUNTRYID NULLIF (COUNTRYID="NULL"),
COUNTRYCODE,
COUNTRYNAME,
CONTINENTID NULLIF (CONTINENTID="NULL"),
MAPID NULLIF (MAPID="NULL"),
CREATETIME DATE "MM/DD/YYYY HH24:MI:SS" NULLIF (CREATETIME="NULL"),
LASTMODIFIEDTIME DATE "MM/DD/YYYY HH24:MI:SS" NULLIF (LASTMODIFIEDTIME="NULL")
)
BEGINDATA
1;"JP";"Japan";1;9;"09/16/2004 16:31:32";NULL
2;"CN";"China";1;10;"09/16/2004 16:31:32";NULL
3;"IN";"India";1;11;"09/16/2004 16:31:32";NULL
4;"AU";"Australia";6;12;"09/16/2004 16:31:32";NULL
5;"CA";"Canada";4;13;"09/16/2004 16:31:32";NULL
6;"US";"United States";4;14;"09/16/2004 16:31:32";NULL
7;"MX";"Mexico";4;15;"09/16/2004 16:31:32";NULL
8;"GB";"United Kingdom";3;16;"09/16/2004 16:31:32";NULL
9;"DE";"Germany";3;17;"09/16/2004 16:31:32";NULL
10;"FR";"France";3;18;"09/16/2004 16:31:32";NULL
11;"IT";"Italy";3;19;"09/16/2004 16:31:32";NULL
12;"ES";"Spain";3;20;"09/16/2004 16:31:32";NULL
13;"FI";"Finland";3;21;"09/16/2004 16:31:32";NULL
14;"SE";"Sweden";3;22;"09/16/2004 16:31:32";NULL
15;"IE";"Ireland";3;23;"09/16/2004 16:31:32";NULL
16;"NL";"Netherlands";3;24;"09/16/2004 16:31:32";NULL
查看本欄目更多精彩內容:http://www.bianceng.cnhttp://www.bianceng.cn/database/Oracle/