OCP-1Z0-051 第152题 union操作的注意事项

来源:互联网 发布:鞍山plc编程培训 编辑:程序博客网 时间:2024/06/06 03:59
一、原题
Which statement is true regarding the UNION operator?
A. By default, the output is not sorted.
B. NULL values are not ignored during duplicate checking.
C. Names of all columns must be identical across all SELECT statements.
D. The number of columns selected in all SELECT statements need not be the same.

答案:B

二、题目翻译
关于UNION操作符哪句话正确?
A.默认输出不排序。
B.在重复值检查时不忽略NULL值。
C.列名在所有SELECT语句中必须是相同的。
D.在所有SELECT语句中选择的列的数量不需要相同。

三、题目解析
A选项不正确,因为默认输出排序。
B选项正确,因为集合不忽略null值,并且在去重时会认为null和null是相等的,去重。
C选项不正确,因为SELECT语句中的列名不必是相同的,但是数据类型是需要匹配的。
D选项不正确,因为列的数量要相同。

四、测试

SQL> create table t1(id int);

Table created.

SQL> insert into t1 values(1);

1 row created.

SQL> insert into t1 values(null);

1 row created.

SQL> commit;

Commit complete.

SQL> select * from t1;
        ID
----------
         1


2 rows selected.

SQL> create table t2(id int);

Table created.

SQL> insert into t2 values(2);

1 row created.

SQL> insert into t2 values(null);

1 row created.

SQL> commit;

Commit complete.

SQL> select * from t2;

        ID
----------
         2


2 rows selected.

SQL> select * from t1
  2  union
  3  select * from t2; 

       ID
----------
         1
         2


3 rows selected.
       两行null,已经去掉了一行,表示去重时,不忽略空值。


SQL> select id,null from t1
  2  union
  3  select id from t2;
select id,null from t1
*
ERROR at line 1:
ORA-01789: query block has incorrect number of result columns
      列的数量和类型必须一致。

S
QL> select id nid from t1
  2  union
  3  select id from t2;

       NID
----------
         1
         2


3 rows selected.
      名字可以不一致。
 
 
0 0
原创粉丝点击