Oracle with as使用小节

来源:互联网 发布:视差js原理 编辑:程序博客网 时间:2024/06/07 00:25

Oracle中的with as使用

1.前言

Oracle 数据库中的操作 with as 是一个子查询,该子查询是将查询的数据放入Oracle的临时表中,为后续查询提供筛选数据。

2.基本语法

with tempTablbeName  as (select * from table1)select * from tempTablbeName

需要注意的是,with as 是和select 配合使用的,因为临时表创建了就为查询使用的,如果后续没有select查询语句Oracle会报错

2.1创建一个临时表

with temp as (select * from tb_name)

2.2创建多个临时表

with temp1 as(select * from tb_name1),     temp2 as(select * from tb_name1),     temp3 as(select * from tb_name1)

3.扩展

with as 子查询与union配合使用,可以提高查询的灵活性,常见形式如下

with table1 as(                    select 1 as a from dual                    union                    select 2 as a from dual                    union                    select 2 as a from dual               )

4.结束语

with as 创建的临时表,是放到Oracle中的临时表空间中,查询完毕后就被清除了。关于临时表空间和表空间是另外的知识了