一、原题
二、题目翻译
三、题目解析
四、测试
SQL> create table emp3 as select * from emp where 1=0;
Table created.
-- values中的子查询如果返回一行,则能插入成功:
SQL> insert into emp3(empno,ename,deptno) values(1234,'aaa',(select deptno from emp where ename='SCOTT'));
1 row created.
-- values中的子查询如果返回多行,则插入失败:
SQL> insert into emp3(empno,ename,deptno) values(1234,'aaa',(select deptno from emp where deptno=10));
insert into emp3(empno,ename,deptno) values(1234,'aaa',(select deptno from emp where deptno=10))
*
ERROR at line 1:
ORA-01427: single-row subquery returns more than one row
View the exhibit and examine the description for the SALES and CHANNELS tables.
![](https://img-blog.csdn.net/20140523182951781?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvaG9sbHkyMDA4/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast)
You issued the following SQL statement to insert a row in the SALES table:
INSERT INTO sales
VALUES
(23,
2300,
SYSDATE,
(SELECT channel_id FROM channels WHERE channel_desc = 'Direct Sales'),
12,
1,
500);
Which statement is true regarding the execution of the above statement?
A. The statement will execute and the new row will be inserted in the SALES table.
B. The statement will fail because subquery cannot be used in the VALUES clause.
C. The statement will fail because the VALUES clause is not required with subquery.
D. The statement will fail because subquery in the VALUES clause is not enclosed with in single quotation marks
答案:A
You issued the following SQL statement to insert a row in the SALES table:
INSERT INTO sales
VALUES
(23,
2300,
SYSDATE,
(SELECT channel_id FROM channels WHERE channel_desc = 'Direct Sales'),
12,
1,
500);
Which statement is true regarding the execution of the above statement?
A. The statement will execute and the new row will be inserted in the SALES table.
B. The statement will fail because subquery cannot be used in the VALUES clause.
C. The statement will fail because the VALUES clause is not required with subquery.
D. The statement will fail because subquery in the VALUES clause is not enclosed with in single quotation marks
答案:A
二、题目翻译
查看SALES and CHANNELS表的结构
执行下面的SQL语句给SALES表插入一行:
关于执行上面的语句哪句话是正确的?
A.语句执行成功,并且SALES表会插入一个新行。
B.语句失败,因为子查询不能用于VALUES子句中。
C.语句失败,因为VALUES子句不需要使用子查询。
D.语句失败,因为VALUES子句中的子查询没有使用单引号引起来。
执行下面的SQL语句给SALES表插入一行:
关于执行上面的语句哪句话是正确的?
A.语句执行成功,并且SALES表会插入一个新行。
B.语句失败,因为子查询不能用于VALUES子句中。
C.语句失败,因为VALUES子句不需要使用子查询。
D.语句失败,因为VALUES子句中的子查询没有使用单引号引起来。
三、题目解析
A选项,答案是正确的,如果子查询中只返回一行,则这个答案正确,如果子查询中返回多行,就会报错,但相比其它答案,只有这个还算比较正确。
B选项不正确,values子句中,可以使用子查询,详见下面。
C选项不正确,需不需要使用子查询,是业务需求决定的。
D选项不正确,子查询使用括号,而不是单引号。
B选项不正确,values子句中,可以使用子查询,详见下面。
C选项不正确,需不需要使用子查询,是业务需求决定的。
D选项不正确,子查询使用括号,而不是单引号。
四、测试
SQL> create table emp3 as select * from emp where 1=0;
Table created.
-- values中的子查询如果返回一行,则能插入成功:
SQL> insert into emp3(empno,ename,deptno) values(1234,'aaa',(select deptno from emp where ename='SCOTT'));
1 row created.
-- values中的子查询如果返回多行,则插入失败:
SQL> insert into emp3(empno,ename,deptno) values(1234,'aaa',(select deptno from emp where deptno=10));
insert into emp3(empno,ename,deptno) values(1234,'aaa',(select deptno from emp where deptno=10))
*
ERROR at line 1:
ORA-01427: single-row subquery returns more than one row