首页 > 技术文章 > Oracle 临时表 sql 简单的应用

renxinghua 2020-03-16 10:54 原文

Oracle临时表的创建有以下两种:
(1)会话特有的临时表
create global temporany table 表名(
字段名 数据类型,字段名 数据类型,......)
on commit preserve rows;
例:
create global temporany table test1(
user_cd varchar(32),user_name varchar(100),job_date date)
on commit preserve rows;
(2)事务特有的临时表
create global temporany table 表名(
字段名 数据类型,字段名 数据类型,......)
on commit delete rows;
例:
create global temporany table test1(
user_cd varchar(32),user_name varchar(100),job_date date)
on commit delete rows;

创建后就可以插入数据了。

两种临时表的不同在于:
事务特有的临时表在commit后会清空所有行;会话特有的临时表在commit后不会清空数据,而是在会话结束后清空数据。

推荐阅读