一、原题
二、题目翻译
三、题目解析
四、测试
SQL> create table emp2 as select * from emp;
Table created.
SQL> insert into emp2 select * from emp;
14 rows created.
子查询,也可以使用在create,insert等语句中。
SQL> select deptno,sal from emp where sal>(select sal from emp where ename='SCOTT');
DEPTNO SAL
---------- ----------
10 5000
SQL> select deptno,sal from emp where (job,sal) > (select job,sal from emp where ename='SCOTT');
select deptno,sal from emp where (job,sal) > (select job,sal from emp where ename='SCOTT')
*
ERROR at line 1:
ORA-01796: this operator cannot be used with lists
非等值操作,只能有一列,不能有多列。
等值操作就可以有多列。
Which two statements about sub queries are true? (Choose two.)
A. A sub query should retrieve only one row.
B. A sub query can retrieve zero or more rows.
C. A sub query can be used only in SQL query statements.
D. Sub queries CANNOT be nested by more than two levels.
E. A sub query CANNOT be used in an SQL query statement that uses group functions.
F. When a sub query is used with an inequality comparison operator in the outer SQL statement,
the column list in the SELECT clause of the sub query should contain only one column.
答案: B,F
A. A sub query should retrieve only one row.
B. A sub query can retrieve zero or more rows.
C. A sub query can be used only in SQL query statements.
D. Sub queries CANNOT be nested by more than two levels.
E. A sub query CANNOT be used in an SQL query statement that uses group functions.
F. When a sub query is used with an inequality comparison operator in the outer SQL statement,
the column list in the SELECT clause of the sub query should contain only one column.
答案: B,F
二、题目翻译
下面关于子查询的说法,哪两个是正确的?(选择两项)
A.子查询只能返回一行。
B.子查询可以返回0行或多行。
C.子查询只能用在sql查询语句中。
D.子查询不能被嵌套两层以上。
E.子查询不能用在有组函数的查询语句中。
F.子查询使用在一个非等值操作时,子查询中的select后的列只能有一列。
A.子查询只能返回一行。
B.子查询可以返回0行或多行。
C.子查询只能用在sql查询语句中。
D.子查询不能被嵌套两层以上。
E.子查询不能用在有组函数的查询语句中。
F.子查询使用在一个非等值操作时,子查询中的select后的列只能有一列。
三、题目解析
子查询可以返回0行或多行,而且,子查询不仅可以用在select语句中,而且,可以用在delete,insert,update,create等语句中;子查询使用在非等值操作时,子查询中的select后的列只能有一列。
四、测试
SQL> create table emp2 as select * from emp;
Table created.
SQL> insert into emp2 select * from emp;
14 rows created.
子查询,也可以使用在create,insert等语句中。
SQL> select deptno,sal from emp where sal>(select sal from emp where ename='SCOTT');
DEPTNO SAL
---------- ----------
10 5000
SQL> select deptno,sal from emp where (job,sal) > (select job,sal from emp where ename='SCOTT');
select deptno,sal from emp where (job,sal) > (select job,sal from emp where ename='SCOTT')
*
ERROR at line 1:
ORA-01796: this operator cannot be used with lists
非等值操作,只能有一列,不能有多列。
SQL> select deptno,sal from emp where (job,sal)=(select job,sal from emp where ename='SCOTT');
DEPTNO SAL
---------- ----------
20 3000
20 3000
---------- ----------
20 3000
20 3000
等值操作就可以有多列。