博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
oracle中create table with as和insert into with as语句
阅读量:5968 次
发布时间:2019-06-19

本文共 2619 字,大约阅读时间需要 8 分钟。

oracle支持使用with as 子句来创建表

语法:
create table table_name as
with clause_name as
(select query )
[, clause_name1 as
(select query ) ...]
select column1,...columnn from clause_name;

语法:

insert into table_name
with clause_name as
(select query )
[, clause_name1 as
(select query ) ...]
select column1,...columnn from clause_name;

例子:

--create with 语句

CREATE TABLE w_test_20 AS WITH  data_info_19 AS   (SELECT          NVL(ename,'unknow employee') AS ename,          DECODE(deptno,10,'ACCOUNTING',20,'RESEARCH',30,'SALES',40,'OPERATIONS','no this department') AS dname,         NVL(job,'unkown job') AS job ,         substr(to_char(hiredate,'yyyy-mm-dd'),1,7) AS hiredate,         CASE WHEN sal <= 1000 THEN 'D'               WHEN sal > 1000 AND sal <= 2000 THEN 'C'              WHEN sal > 2000 AND sal <= 3000 THEN 'B'              WHEN sal > 3000  THEN 'A'              ELSE 'unkown grade'          END AS grade,         ROUND(sal,2) AS sal,         FLOOR(nvl(comm,0)) AS comm,         NVL(sal,0)+NVL(comm,0) AS total_sal     FROM emp WHERE deptno IN      (SELECT DISTINCT deptno FROM dept)) SELECT * FROM data_info_19;
CREATE TABLE w_test_18 AS WITH dept_info AS (SELECT deptno AS deptno_1,dname FROM dept),emp_info AS(SELECT empno AS empno_1,ename,job,deptno FROM emp),other_info AS(SELECT empno,hiredate,NVL(sal,0)+NVL(comm,0) AS total_sal FROM emp )SELECT * FROM dept_info d LEFT JOIN emp_info e ON d.deptno_1=e.deptno RIGHT JOIN other_info o ON e.empno_1=o.empno ;
INSERT INTO w_test_19WITH  data_info_19 AS   (SELECT          NVL(ename,'unknow employee') AS ename,          DECODE(deptno,10,'ACCOUNTING',20,'RESEARCH',30,'SALES',40,'OPERATIONS','no this department') AS dname,         NVL(job,'unkown job') AS job ,         substr(to_char(hiredate,'yyyy-mm-dd'),1,7) AS hiredate,         CASE WHEN sal <= 1000 THEN 'D'               WHEN sal > 1000 AND sal <= 2000 THEN 'C'              WHEN sal > 2000 AND sal <= 3000 THEN 'B'              WHEN sal > 3000  THEN 'A'              ELSE 'unkown grade'          END AS grade,         ROUND(sal,2) AS sal,         FLOOR(nvl(comm,0)) AS comm,         NVL(sal,0)+NVL(comm,0) AS total_sal     FROM emp WHERE deptno IN      (SELECT DISTINCT deptno FROM dept)) SELECT * FROM data_info_19;
INSERT INTO  w_test_18 WITH dept_info AS (SELECT deptno AS deptno_1,dname FROM dept),emp_info AS(SELECT empno AS empno_1,ename,job,deptno FROM emp),other_info AS(SELECT empno,hiredate,NVL(sal,0)+NVL(comm,0) AS total_sal FROM emp )SELECT * FROM dept_info d LEFT JOIN emp_info e ON d.deptno_1=e.deptno RIGHT JOIN other_info o ON e.empno_1=o.empno ;

转载于:https://blog.51cto.com/mjal01/2045746

你可能感兴趣的文章
git忽略文件【转】
查看>>
Web上的支持的图片格式以及它们之间的区别
查看>>
jQuery监听文本框值改变触发事件(propertychange)
查看>>
HDU--2040
查看>>
甲骨文Java Archive
查看>>
查看数据库错误日志的位置
查看>>
电信网络拓扑图自动布局
查看>>
C#中List〈string〉和string[]数组之间的相互转换
查看>>
洛谷P1108 低价购买[DP | LIS方案数]
查看>>
通达信里的统计函数及区块背景函数
查看>>
redis主从配置<转>
查看>>
8 行 Node.js 代码实现代理服务器
查看>>
水印,图片验证码
查看>>
C#编程(七十六)----------使用指针实现基于栈的高性能数组
查看>>
PostgreSql 分页limit
查看>>
在MySQL中创建cm-hive使用的数据库及账号
查看>>
linux下限制ip访问
查看>>
linux添加环境变量
查看>>
ASP.NET MVC 入门8、ModelState与数据验证
查看>>
组件居中显示 安卓
查看>>