临时表,外部表

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
# 文件导入成功

 

转载于:https://my.oschina.net/wangzilong/blog/803388

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值