zoukankan      html  css  js  c++  java
  • insert into (select...WITH CHECK OPTION) values(...)

    insert into (<subquery> WITH CHECK OPTION) values (...)

    语法看起来很特殊,其实是insert进subquery的这张表里:

    1. 只有插入的值在subquery列表中,且满足where条件时才能插入成功。

    2. 如果不满足subquery里的where条件的话,就不允许插入。

    3. 如果插入的列不在subquery里,那么也会不允许插入。

    4. 如果不加WITH CHECK OPTION则在插入时不会检查。

    5. subquery其实是不会实际执行的。

    //满足条件,成功插入

    SQL> insert into (select deptno,dname from dept where deptno>50 with check option) values (90,'Tough');
    已创建 1 行。

    //deptno=45不满足where子句条件

    SQL> insert into (select deptno,dname from dept where deptno>50 with check option) values (45,'Tough');

    insert into (select deptno,dname from dept where deptno>50 with check option) values (45,'Tough')
                                          *
    第 1 行出现错误:
    ORA-01402: 视图 WITH CHECK OPTIDN where 子句违规

    //插入的值不在subquery列表中,多值或少值都不行

    SQL> insert into (select deptno,dname from dept where deptno>50 with check option) values (90,'Tough','TH');

    insert into (select deptno,dname from dept where deptno>50 with check option) values (90,'Tough','TH')
                *
    第 1 行出现错误:
    ORA-00913: 值过多


    SQL> insert into (select deptno,dname from dept where deptno>50 with check option) values (90);

    insert into (select deptno,dname from dept where deptno>50 with check option) values (90)
                *
    第 1 行出现错误:
    ORA-00947: 没有足够的值

    //不加WITH CHECK OPTION则在插入时不会检查

    SQL> insert into (select deptno,dname from dept where deptno>50) values (45,'Tough');
    已创建 1 行。

    //subquery其实是不会实际执行的。从执行计划可以看出来

    SQL> insert into (select deptno,dname from dept where deptno>50 with check option) values (91,'Tough');
    已创建 1 行。

    执行计划
    ----------------------------------------------------------

    -------------------------------------------------------------------------
    | Id  | Operation        | Name | Rows  | Bytes | Cost (%CPU)| Time     |
    -------------------------------------------------------------------------
    |   0 | INSERT STATEMENT |      |     1 |    20 |     1   (0)| 00:00:01 |
    -------------------------------------------------------------------------

     


     

     

  • 相关阅读:
    [Debug] Make python2.7 use the right version of opencv
    路线图 | 学习OpenCV路线图
    学习笔记 | Princeton
    书单 | 2017年阅读书单
    路线图 | 摄影师成长路线
    学习笔记 | Morvan
    如何在pycharm中进入shell脚本调试代码
    python3运行报错:TypeError: Object of type 'type' is not JSON serializable解决方法(详细)
    动态规划的引入 P1616 疯狂的采药【完全背包】
    动态规划的引入 P1048 采药【01背包】
  • 原文地址:https://www.cnblogs.com/toughhou/p/3778799.html
Copyright © 2011-2022 走看看