SUMSEN

Oracle&Sql爱好者,用友NC管理员

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

前面的博客实验做了sqlldr load,那个是导入外部的excel(txt)到oracle数据库,如果不需要导入到oracle,仅仅是访问(当做外部表),可以使用oracle_loader。

1,创建目录directory sys下

SYS@ncbeta>create or replace directory su as 'd:\tbt'; --su是目录名

目录已创建。

SYS@ncbeta>select owner,DIRECTORY_NAME,DIRECTORY_PATH from dba_directories;

 上述命令可以看到所有的directory

SYS@ncbeta>drop directory su; --删除directory

目录已删除。

2,目录下有这么一个txt,学生成绩表,这里最后一行詹国坤math没有成绩

3,写sql  发现了terminated错误,可是为什么还给建表了

16:44 更新

确定了,去除后面的--备注就ok

create table ex_stu
(name varchar2(10),
 subject varchar2(10),
 score number(3))
organization external
( type oracle_loader default directory su
 access parameters
( records delimited by newline
logfile  su:'ex_sut_log.log' --这里su:可以不用输入
fields terninated by ','
missing field values are null --詹国坤没有成绩null处理
(name,subject,score))
location ('student.txt'))  --这里两个))
parallel reject limit unlimited ;

3,表创建了,但是select报错,并且logfile没有生成

使用查询外部表SYS@ncbeta>select owner,table_name,location, DIRECTORY_NAME from dba_external_locations;

 在其他用户下创建也不行

SYS@ncbeta>grant read,write on directory su to ncv5;

这种用法是在ncv5下建表用的

 create table ncv5.ex_stu



授权成功。

16:06 更新

 让倪瑞同学测试,她ok了,按照她的说法,她给我排版了

 create table ex_stu
(name varchar2(20),
 subject varchar2(10),
 score number(3))
organization external
(type oracle_loader
 default directory su
 access parameters(
 records delimited by newline
 logfile 'ex_sut.log' 
 fields terminated by ','
 missing field values are null
(name,subject,score))
location ('student.txt'));
不过这次还好,终于产生了log文件

 LOG file opened at 01/07/13 15:53:49

Field Definitions for table EX_STU
  Record format DELIMITED BY NEWLINE
  Data in file has same endianness as the platform
  Rows with all null fields are accepted

  Fields in Data Source:

    NAME                            CHAR (255)
      Terminated by ","
      Trim whitespace same as SQL Loader
    SUBJECT                         CHAR (255)
      Terminated by ","
      Trim whitespace same as SQL Loader
    SCORE                           CHAR (255)
      Terminated by ","
      Trim whitespace same as SQL Loader
error processing column NAME in row 5 for datafile d:\xs\student.txt
ORA-12899: value too large for column NAME (actual: 11, maximum: 10)
原来是zhangyuntao占了11个字符,varchar2(10)少了
改成20就行了
 
 

 

posted on 2013-01-07 11:15  sumsen  阅读(2207)  评论(0编辑  收藏  举报