您在这里:首页 > 学员专区 > 技术文章
Oracle视频
Oracle
CUUG课程

sql loader使用例子

 

一、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

17;"DK";"Denmark";3;25;"09/16/2004 16:31:32";NULL

18;"BR";"Brazil";5;85;"09/30/2004 11:25:43";NULL

19;"KR";"Korea, Republic of";1;88;"09/30/2004 11:25:43";NULL

20;"NZ";"New Zealand";6;89;"09/30/2004 11:25:43";NULL

21;"BE";"Belgium";3;79;"09/30/2004 11:25:43";NULL

22;"AT";"Austria";3;78;"09/30/2004 11:25:43";NULL

23;"NO";"Norway";3;82;"09/30/2004 11:25:43";NULL

24;"LU";"Luxembourg";3;81;"09/30/2004 11:25:43";NULL

25;"PT";"Portugal";3;83;"09/30/2004 11:25:43";NULL

26;"GR";"Greece";3;80;"09/30/2004 11:25:43";NULL

27;"IL";"Israel";1;86;"09/30/2004 11:25:43";NULL

28;"CH";"Switzerland";3;84;"09/30/2004 11:25:43";NULL

29;"A1";"Anonymous Proxy";0;0;"09/30/2004 11:25:43";NULL

30;"A2";"Satellite Provider";0;0;"09/30/2004 11:25:43";NULL

31;"AD";"Andorra";3;0;"09/30/2004 11:25:43";NULL

32;"AE";"United Arab Emirates";1;0;"09/30/2004 11:25:43";NULL

33;"AF";"Afghanistan";1;0;"09/30/2004 11:25:43";NULL

34;"AG";"Antigua and Barbuda";7;0;"09/30/2004 11:25:43";NULL

35;"AI";"Anguilla";7;0;"09/30/2004 11:25:43";NULL

36;"AL";"Albania";3;0;"09/30/2004 11:25:43";NULL

37;"AM";"Armenia";3;0;"09/30/2004 11:25:43";NULL

38;"AN";"Netherlands Antilles";3;0;"09/30/2004 11:25:43";NULL

39;"AO";"Angola";2;0;"09/30/2004 11:25:43";NULL

40;"AP";"Asia/Pacific Region";2;0;"09/30/2004 11:25:43";NULL

41;"AQ";"Antarctica";8;0;"09/30/2004 11:25:43";NULL

42;"AR";"Argentina";5;0;"09/30/2004 11:25:43";NULL

43;"AS";"American Samoa";6;0;"09/30/2004 11:25:43";NULL

44;"AW";"Aruba";5;0;"09/30/2004 11:25:43";NULL

45;"AZ";"Azerbaijan";1;0;"09/30/2004 11:25:43";NULL

46;"BA";"Bosnia and Herzegovina";3;0;"09/30/2004 11:25:43";NULL

47;"BB";"Barbados";5;0;"09/30/2004 11:25:43";NULL

48;"BD";"Bangladesh";1;0;"09/30/2004 11:25:43";NULL

49;"BF";"Burkina Faso";2;0;"09/30/2004 11:25:43";NULL

50;"BG";"Bulgaria";3;0;"09/30/2004 11:25:43";NULL

51;"BH";"Bahrain";1;0;"09/30/2004 11:25:43";NULL

52;"BI";"Burundi";2;0;"09/30/2004 11:25:43";NULL

53;"BJ";"Benin";2;0;"09/30/2004 11:25:43";NULL

54;"BM";"Bermuda";4;0;"09/30/2004 11:25:43";NULL

55;"BN";"Brunei Darussalam";1;0;"09/30/2004 11:25:43";NULL

56;"BO";"Bolivia";5;0;"09/30/2004 11:25:43";NULL

57;"BS";"Bahamas";7;0;"09/30/2004 11:25:43";NULL

58;"BT";"Bhutan";1;0;"09/30/2004 11:25:43";NULL

59;"BV";"Bouvet Island";5;0;"09/30/2004 11:25:43";NULL

60;"BW";"Botswana";2;0;"09/30/2004 11:25:43";NULL

61;"BY";"Belarus";3;0;"09/30/2004 11:25:43";NULL

2、执行导入命令

C:\>sqlldr userid=system/manager control=test.ctl

相关文章 [上一篇] sql loader的应用(二)
010-88589926(88587026)
CUUG热门培训课程
Oracle DBA就业培训
CUUG名师
网络课程
技术沙龙
最新动态

总机:(010)-88589926,88589826,88587026 QQ讨论群:243729577 182441349 邮箱:cuug_bj@cuug.com
通信地址:北京市海淀区紫竹院路98号北京化工大学科技园609室(CUUG)邮政编码:100089 
中国UNIX用户协会 Copyright 2010  ALL Rights Reserved 北京神脑资讯技术有限公司
京ICP备11008061号  京公网安备110108006275号