标签:sqlloader
一创建目录
先在系统下创建
$ cd /home/oracle $ mkdir dir $ cd dir $ pwd
再在sqlplus里创建,让oracle知道这个目录
SQL> createdirectory dir as ‘/home/oracle/dir‘;
最后授权
SQL> grant all ondirectory dir to public;
二创建数据源文件
$ cd dir
$ vi prod_my.data 360,Jane,Janus,ST_CLERK,121,17-MAY-2001,3000,0,50,jjanus 361,Mark,Jasper,SA_REP,145,17-MAY-2001,8000,.1,80,mjasper 362,Brenda,Starr,AD_ASST,200,17-MAY-2001,5500,0,10,bstarr 363,Alex,Alda,AC_MGR,145,17-MAY-2001,9000,.15,80,aalda 401,Jesse,Cromwell,HR_REP,203,17-MAY-2001,7000,0,40,jcromwel 402,Abby,Applegate,IT_PROG,103,17-MAY-2001,9000,.2,60,aapplega 403,Carol,Cousins,AD_VP,100,17-MAY-2001,27000,.3,90,ccousins 404,John,Richardson,AC_ACCOUNT,205,17-MAY-2001,5000,0,110,jrichard
查看
$ cat prod_my.data
三创建外部表external
CREATE TABLEscott.prod_my( c1 number(5), c2 varchar2(20), c3 varchar2(20), c4 varchar2(30), c5 number(5), c6 date, c7 number(8,3), c8 number(5,2), c9 number(5,2), c10 varchar2(30) ) ORGANIZATION EXTERNAL (TYPE ORACLE_LOADERDEFAULT DIRECTORY dir ACCESS PARAMETERS(FIELDS TERMINATED BY "," OPTIONALLY ENCLOSED BY ‘"‘ MISSING FIELD VALUES ARE NULL) LOCATION(‘prod_my.data‘));
解释
FIELDS TERMINATED BY"," 代表列与列之间用 ","单引号分割
OPTIONALLY ENCLOSED BY"" 代表列值是一句话用("")双引号引起来
MISSING FIELD VALUES ARENULL 代表(,,)逗号与逗号之间可以是空值
四查询外部表
col c2 for a8 col c3 for a10 col c4 for a10 col c10 for a10 selectc1,c2,c3,c5,c6,c7,c8,c9 from scott.prod_my; C1 C2 C3 C5 C6 C7 C8 C9 ---------- ------------------ ---------- --------- ---------- ---------- ---------- 360 Jane Janus 121 17-MAY-01 3000 0 50 361 Mark Jasper 145 17-MAY-01 8000 .1 80 362 Brenda Starr 200 17-MAY-01 5500 0 10 363 Alex Alda 145 17-MAY-01 9000 .15 80 401 Jesse Cromwell 203 17-MAY-01 7000 0 40 402 Abby Applegate 103 17-MAY-01 9000 .2 60 403 Carol Cousins 100 17-MAY-01 27000 .3 90 404 John Richardson 205 17-MAY-01 5000 0 110
select* from scott.prod_my; 查看全部信息
然后将外部表导入到数据库中
一先创建实体的表
CREATE TABLEscott.ldr( c1 number(5), c2 varchar2(20), c3 varchar2(20), c4 varchar2(30), c5 number(5), c6 date, c7 number(8,3), c8 number(5,2), c9 number(5,2), c10 varchar2(30) );
二再创建sqlloader控制文件
$ cd dir $ vi ldr.ctl load data infile‘prod_my.data‘ append into table scott.ldr fields terminated by‘,‘ optionally enclosedby ‘"‘ TRAILING NULLCOLS ( c1, c2, c3, c4, c5, c6, c7, c8, c9, c10 )
开始导入
/u01/app/oracle/product/11gr2/db_1/bin
[oracle@HE3bin]$ ./sqlldr scott/tiger control=‘/home/oracle/sqlloader/ldr.ctl‘log=‘/home/oracle/sqlloader/ldr.log‘
第一步先问文件的位置查处后,修改 infile【/home/oracle/dir/prod_my.data】
第二步再创建实体的表建立后输入表名 into table 【scott.ldr】
第三步在infile ‘prod_my.data‘下面,加入一个参数【append】
第四步增加一行TRAILING NULLCOLS,
注意:最后不要加【 ; 】分号结束,否则会报错
解释
append:代表如果表里有数据可以继续添加
TRAILINGNULLCOLS:代表可以将空行干掉
(由于回车产生,也就是空行)
标签:sqlloader
原文地址:http://suifu.blog.51cto.com/9167728/1731255