• Oracle使用子查询一次性更新或插入多条语句


    1.insert子查询

    以下例子先创建一个表,然后把已有表emp中的数据插入到该表中。

    SQL> create table mytab(id number(4),ename varchar2(20),deptno number(4));

    表已创建。

    SQL> desc emp;
    名称                                      是否为空? 类型
    ----------------------------------------- -------- ----------------------------

    EMPNO                                     NOT NULL NUMBER(4)
    ENAME                                              VARCHAR2(10)
    JOB                                                VARCHAR2(9)
    MGR                                                NUMBER(4)
    HIREDATE                                           DATE
    SAL                                                NUMBER(7,2)
    COMM                                               NUMBER(7,2)
    DEPTNO                                             NUMBER(2)

    SQL> insert into mytab select empno,ename,deptno from emp where deptno=10;

    已创建3行。

    SQL> select * from mytab;

            ID ENAME                                        DEPTNO
    ---------- ---------------------------------------- ----------
          7782 CLARK                                            10
          7839 KING                                             10
          7934 MILLER                                           10

    SQL>

    2.update子查询

    更新SCOTT的岗位、工资、奖金都与SMITH一样。

    update emp set job=(select job from emp where ename='SMTIH') ,
    sal=(select sal from emp where ename='SMTIH')

    where ename='SCOTT';


    update emp set(job,sal,comm) =(select job,sal,comm from emp where ename='SMITH') where ename='SCOTT';

  • 相关阅读:
    菜鸟系列k8s——快速部署k8s集群(3)
    菜鸟系列docker——docker容器(7)
    菜鸟系列Fabric源码学习 — 区块同步
    菜鸟系列Fabric源码学习 — peer节点启动
    菜鸟系列Fabric源码学习 — orderer服务启动
    递归科赫雪花
    汉诺塔递归函数hanoi
    字符串格式化与.format()
    turtle风轮绘制
    接口签名2
  • 原文地址:https://www.cnblogs.com/tazi/p/2311578.html
Copyright © 2020-2023  润新知