oracle中createtablewithas和insertintowithas语句

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_19
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;
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 ;

当前名称:oracle中createtablewithas和insertintowithas语句
本文URL:http://lszwz.com/article/isjipj.html

其他资讯

售后响应及时

7×24小时客服热线

数据备份

更安全、更高效、更稳定

价格公道精准

项目经理精准报价不弄虚作假

合作无风险

重合同讲信誉,无效全额退款