<< 返回文章列表
Oracle 20c 新特性:ANSI SQL 全支持之 EXCEPT 运算符增强
2020年4月22日
盖国强
161
墨天轮原文链接:https://www.modb.pro/db/24419
在 Oracle 20c 中,Oracle 增加了对于集合运算符的增强,全部支持了 ANSI SQL 标准的关键字,新增了 EXCEPT 关键字支持。
SQL 集合操作支持 ANSI SQL 标准的所有关键字
20c 支持了 EXCEPT [ALL] 关键字 (等价 MINUS [ALL])
同时 MINUS 和 INTERSECT 支持关键字 ALL.
全 ANSI 标准支持,提高了迁移到 Oracle 数据库的兼容性
来看一个简单的测试,创建两个测试表:
[oracle@enmotech ~]$ sqlplus / as sysdba SQL*Plus: Release 20.0.0.0.0 - Production on Tue Apr 21 07:42:20 2020 Version 20.2.0.0.0 Copyright (c) 1982, 2020, Oracle. All rights reserved. Connected to: Oracle Database 20c Enterprise Edition Release 20.0.0.0.0 - Production Version 20.2.0.0.0 SQL> create table enmo(id number,name varchar2(20)); Table created. SQL> create table yhem(id number,name varchar2(20)); Table created. SQL> insert into enmo values(1,'EYGLE'); 1 row created. SQL> insert into yhem values(1,'EYGLE'); 1 row created. SQL> insert into enmo values(2,'KAMUS'); 1 row created. SQL> insert into yhem values(2,'KAMUS'); 1 row created. SQL> insert into yhem values(3,'YANGTINGKUN'); 1 row created. SQL> insert into yhem values(4,'ORA-600'); 1 row created.
EXCEPT 和 MINUS 等价比较:
SQL> select * from yhem 2 minus 3 select * from enmo; ID NAME ---------- -------------------- 3 YANGTINGKUN 4 ORA-600 SQL> select * from yhem 2 except 3 select * from enmo; ID NAME ---------- -------------------- 3 YANGTINGKUN 4 ORA-600 SQL> select * from enmo 2 minus 3 select * from yhem; no rows selected SQL> insert into enmo values(5,'LAOXIONG'); 1 row created. SQL> select * from enmo 2 minus 3 select * from yhem; ID NAME ---------- -------------------- 5 LAOXIONG SQL> select * from enmo 2 except 3 select * from yhem; ID NAME ---------- -------------------- 5 LAOXIONG
EXCEPT 通过 ALL 关键字显示所有差异记录,不去重复值:
SQL> insert into yhem values(4,'ORA-600'); 1 row created. SQL> select * from yhem 2 except 3 select * from enmo; ID NAME ---------- -------------------- 3 YANGTINGKUN 4 ORA-600 SQL> select * from yhem 2 except all 3 select * from enmo; ID NAME ---------- -------------------- 3 YANGTINGKUN 4 ORA-600 4 ORA-600
这是 Oracle 20c 中关于 SQL 关键字方面的小增强。