Oracle 11g 数据装载的几种方式(2)

Table STUDENT:
  3 Rows successfully loaded.
  1 Row not loaded due to data errors.
  0 Rows not loaded because all WHEN clauses were failed.
  0 Rows not loaded because all fields were null.


Space allocated for bind array:                  66048 bytes(64 rows)
Read  buffer bytes: 1048576

Total logical records skipped:          4
Total logical records read:            4
Total logical records rejected:        1
Total logical records discarded:        0

Run began on Fri Jan 23 23:11:08 2015
Run ended on Fri Jan 23 23:11:08 2015

Elapsed time was:    00:00:00.10
CPU time was:        00:00:00.01
[oracle@localhost test_data_loader]$ sqlplus hr/hr

SQL*Plus: Release 11.2.0.1.0 Production on Fri Jan 23 23:13:14 2015

Copyright (c) 1982, 2009, Oracle.  All rights reserved.


Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL> select * from student;

ID NAME                        AGE INNER_DATE
---------- -------------------- ---------- ------------
        1 zhangsan                    21 23-JAN-15
        2 lisi                        22 23-JAN-15
        3 wangwu                      23 23-JAN-15

SQL> exit

外部表:
外部表中的数据不装入数据库中,数据库中只存储外部表的定义信息,实际的数据位于操作系统的平面文件中,
但是,可以在数据库中,像访问正常表那样,通过select语句来访问操作系统中的平面文件中所含有的数据。
外部表是只读的。
可以使用SQL,PL/SQL和JAVA访问外部表。
外表表分为2种:使用数据泵引擎生成的外部表、

SQL> create table student_re(re_id,re_name,re_age,re_inner_date)
organization external
(
type oracle_datapump--外部表生成方式是数据泵
default directory test_impdp_expdp--默认的路径
location('student.dmp')--通过路径和文件名生成外部表在操作系统的平面数据文件
)
parallel--并行
as
select * from student;  2    3    4    5    6    7    8    9  10

Table created.

SQL> !ls
student.dmp  STUENT_17109.log
SQL>  select * from stuent;

RE_ID RE_NAME                  RE_AGE RE_INNER_DAT
---------- -------------------- ---------- ------------
        1 zhangsan                    21 23-JAN-15
        2 lisi                        22 23-JAN-15
        3 wangwu                      23 23-JAN-15

SQL>

根据文本文件创建的外部表。
SQL> spool student.txt

ID||','||NAME||','||AGE||','||INNER_DATE
--------------------------------------------------------------------------------
1,zhangsan,21,23-JAN-15
2,lisi,22,23-JAN-15
3,wangwu,23,23-JAN-15

SQL> exit
Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
[oracle@localhost test_impdp_expdp]$ vi student.txt
[oracle@localhost test_impdp_expdp]$ sqlplus hr/hr

SQL*Plus: Release 11.2.0.1.0 Production on Sat Jan 24 00:05:18 2015

Copyright (c) 1982, 2009, Oracle.  All rights reserved.


Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL> create table student_re_2--该外部表的名称下面列是外部表的建表语句,而上面通过数据泵的表是通过as select from tab来建立的。
  2  (id number,name varchar2(20),age number(10),inner_date date)
  3  organization external
  4  ( type oracle_loader--外部文件方式
  5    default directory test_impdp_expdp--默认的目录
  6    access parameters--访问外部文件所遵守的格式
  7    (
  records delimited by newline--记录分隔符
  fields terminated by ','--字段分隔符
  8    ) location ('student.txt')--位置
  );  9  10  11

Table created.

SQL> select * from student_re_2;

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/09cfa2ba69f6f710047393294ee61724.html