1 临时表
1.1 居于事物的临时表
create global temporary table table_name (column datatype) on commit delete rows;
# 创建一个临时表
create global temporary table tmp_temporary_t1
(name varchar2(20),
sal number
) on commit delete rows;
# 插入数据
insert into tmp_temporary_t1 select 'a',200 from dual;
# 检查数据
NAME SAL
a 200
# 提交数据再检查
commit;
select * from tmp_temporary_t1;
# 提交后就没有数据了。
1.2 居于会话的临时表
create global temporary table table_name(column datatype) on commit preserve rows;
1.3 普通临时表
create gloabl temporary table table_name(column datatype);
需要手动清理里面的数据,默认数据是放在临时表空间里面。
create global temporary table tmp_global_t1
(id number,
age number
);
2 外部表
外部表:数据不是存放在数据库中,而是存放在某个文件中,并且对数据查询的时候引入数据库不占用空间
sqlloader 工具值在sqlplus 导入 将外部数据文件导入,加载文本文件
oracle loader 工具引用外部表,但是不存入数据库存入外部文件,且只能加载二进制文件
oracle datapump
2.1 先建一个表
create table tmp_out_table_1
(loc varchar2(50),
numb number
);
2.2 把数据存放在文件中
[root@myyun1 tmp]# cat 1.txt
zhang,1
wang,2
li,3
zhao,4
2.3 创建一个控制文件ins.ctl
控制文件名字自己随便定义后缀为ctl
[root@myyun1 tmp]# cat ins.ctl
load data
infile '/tmp/1.txt'
into table tmp_out_table_1
truncate
FIELDS TERMINATED BY ','
trailing nullcols
(loc,numb)
运行控制文件
[root@myyun1 oracle]# sqlldr scott/tiger control=/tmp/ins.ctl
SQL*Loader: Release 11.2.0.3.0 - Production on Fri Dec 9 20:58:16 2016
Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.
Commit point reached - logical record count 4
# 检查导入的文件
select * from tmp_out_table_1;
LOC NUMB
zhang 1
wang 2
li 3
zhao 4
# 文件导入成功