现在的位置: 首页 > 综合 > 正文

[每日一题] OCP1z0-047 :2013-08-04 INSERT — WITH CHECK OPTION………………………24

2014年01月29日 ⁄ 综合 ⁄ 共 1364字 ⁄ 字号 评论关闭

转载请注明出处:http://blog.csdn.net/guoyjoe/article/details/9751355

这题是考:insertWITH CHECK OPTION的用法

insert into (<select clause> WITH CHECKOPTION) values (...)

这样的语法看起来有点特点,其实insert是插入到查询里的这张表里,只不过如果不满足子查询里的where条件的话,就不允许插入。如果插入的列有不在子查询作为检查的where条件里,那么也会不允许插入。如果不加WITH CHECK OPTION则在插入时不会检查。

 

OK!我们根据题意先来做测试:

 

SQL> INSERT INTO (SELECT order_id,order_date,customer_id FROM ORDERS
  2  WHERE order_total=1000
  3  WITH CHECK OPTION) VALUES(13,SYSDATE,101);
INSERT INTO (SELECT order_id,order_date,customer_id FROM ORDERS
                                                         *
ERROR at line 1:
ORA-01402: view WITH CHECK OPTION where-clause violation

这里SELECT子查询中没有order_total,是不允许插入的。

 

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

SQL> INSERT INTO (SELECT order_id,order_date,customer_id FROM ORDERS
  2  WHERE order_total=1000) VALUES(130,SYSDATE,101);

1 row created.

正确的应该改成(在select中加入一列order_total):

SQL> INSERT INTO (SELECT order_id,order_date,customer_id,order_total FROM ORDERS
  2  WHERE order_total=1000
  3  WITH CHECK OPTION) VALUES(13,SYSDATE,101,1000);

1 row created.

答案C是正确的。(答案D是说 在SELECT中应该要所有的列,这显然不对,在上个例子上加了一列order_total就搞定了。 )

QQ:252803295

学习交流QQ群:
DSI&Core Search  Ⅰ 群:127149411(技术:已满)
DSI&Core Search  Ⅱ 群:177089463(技术:未满)
DSI&Core Search  Ⅲ 群:284596437(技术:未满)
DSI&Core Search  Ⅳ 群:192136702(技术:未满)
DSI&Core Search  Ⅴ 群:285030382(闲聊:未满)


MAIL:oracledba_cn@hotmail.com

BLOG: http://blog.csdn.net/guoyjoe

WEIBO:http://weibo.com/guoyJoe0218

ITPUB: http://www.itpub.net/space-uid-28460966.html

OCM:   http://education.oracle.com/education/otn/YGuo.HTM

抱歉!评论已关闭.