OCP-1Z0-051 补充题库 第29题 INSERT语句中有子查询

本文讨论了在Oracle数据库中,当尝试使用INSERT语句结合子查询时遇到的问题。文章通过一个具体的题目,解释了为何在INSERT语句中如果包含子查询,不应使用VALUES关键字,并给出了相应的错误示例。同时,还提供了匹配列数量和列名的重要性,帮助理解可能导致插入失败的原因。
一、原题
View the Exhibit and examine the structure of the CUSTOMERS table.

NEW_CUSTOMERS is a new table with the columns CUST_ID, CUST_NAME and CUST_CITY
that have the same data types and size as the corresponding columns in the CUSTOMERS table.
Evaluate the following INSERT statement:

The INSERT statement fails when executed. What could be the reason?
A. The VALUES clause cannot be used in an INSERT with a subquery
B. The total number of columns in the NEW_CUSTOMERS table does not match the total number
of columns in the CUSTOMERS table
C. The WHERE clause cannot be used in a sub query embedded in an INSERT statement
D. Column names in the NEW_CUSTOMERS and CUSTOMERS tables do not match
答案: A

二、题目翻译
下面是CUSTOMERS表的结构。
NEW_CUSTOMERS是一个新表,有CUST_ID, CUST_NAME and CUST_CITY列,和 CUSTOMERS表的数据类型和长度一样。
下面的INSERT语句:
这个INSERT语句会执行失败,是什么原因?
A.VALUES子句不能用在有子查询的INSERT语句中。
B. NEW_CUSTOMERS的列的数量和CUSTOMERS表不匹配。
C.WHERE子句不能用在INSERT语句的子查询中。
D.NEW_CUSTOMERS和 CUSTOMERS表的列名不匹配。

三、题目解析
INSERT语句中,后面有子查询,就不需要带VALUES关键字。

四、测试
       emp2和emp表结构完全一样。

SQL> insert into emp2 select * from emp;

14 rows created.

SQL> insert into emp2 values(select * from emp);
insert into emp2 values(select * from emp)
                        *
ERROR at line 1:
ORA-00936: missing expression

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值