外部表:数据存储在os上,元数据(metadata)存储在数据库中,特点:只读
1.读取外部表的方法
os下创建目录,
mkdir -p /u01/app/oracle/oradata/test/aaa_dir
1)建立txt外部表文件,并放到aaa_dir下
假如有如下的数据文件:
t1.txt文件内容:
7566,JONES,2975 ,20
7698,BLAKE,2850 ,30
7788,SCOTT,3000 ,20
7839,KING ,9000 ,10
7902,FORD ,3000 ,20
2)创建目录,并用DBA进行授权:
sys:
create direcotory test_dir as '/u01/app/oracle/oradata/test/aaa_dir';
grant read,write on directory test_dir to scott;
3)使用被授权的用户scott创建外部表:
create table test_table
(empno int,
ename char(20),
sal int,
deptno int)
organization external
(
type oracle_loader
default directory test_dir
access parameters
(
records delimited by newline
badfile 'bad_dev.txt'
logfile 'log_dev.txt'
fileds terminated by ','
missing filed values are null
(empno,ename,sal,deptno)
)
location('t1.txt')
)
4)进行select操作看是否正确
select * from test_table
select * from test_table where deptno=10;
create table abc as select * from test_table where deptno=20;
create view v2 as select * from test_table where deptno=20;
查看外部表的两个字典试图
dba_external_tables;
dba_external_locations;
select owner,table_name,default_directory_name,access_parameters from dba_external_tables;
考点:
外部表中default directory子句是强制的,不能省略的。
外部表不能做DML操作,不能建立索引、约束、LOB对象,但是可以使用外部表建立表(CTAS)或视图(CVAS)以及同义词。
有2种不同类型的驱动,oracle_loader and oracle_datapump,前者引用的是sql*Loader特性。