20041012oracle学习笔记,注意minus的应用
2004-10-12 12:58
537 查看
The UNION [ALL], INTERSECT, MINUS Operators
You can combine multiple queries using the set operatorsUNION,
UNION
ALL,
INTERSECT, and
MINUS. All set operators have equal precedence. If a SQL statement contains multiple set operators, then Oracle evaluates them from the left to right if no parentheses explicitly specify another order.
The corresponding expressions in the select lists of the component queries of a compound query must match in number and datatype. If component queries select character data, then the datatype of the return values are determined as follows:
If both queries select values of datatype
CHAR, then the returned values have datatype
CHAR.
If either or both of the queries select values of datatype
VARCHAR2, then the returned values have datatype
VARCHAR2.
Restrictions on Set Operators
The set operators are not valid on columns of type
BLOB,
CLOB,
BFILE,
VARRAY, or nested table.
The
UNION,
INTERSECT, and
MINUSoperators are not valid on
LONGcolumns.
If the select list preceding the set operator contains an expression, then you must provide a column alias for the expression in order to refer to it in the
order_by_clause.
You cannot also specify the
for_update_clausewith these set operators.
You cannot specify the
order_by_clausein the
subqueryof these operators.
You cannot use these operators in
SELECTstatements containing
TABLEcollection expressions.
[b]Note:[/b] To comply with emerging SQL standards, a future release of Oracle will give the INTERSECToperator greater precedence than the other set operators. Therefore, you should use parentheses to specify order of evaluation in queries that use the INTERSECToperator with other set operators. |
UNION Example
The following statement combines the results with the
UNIONoperator, which eliminates duplicate selected rows. This statement shows that you must match datatype (using the
TO_CHARfunction) when columns do not exist in one or the other table:
SELECT location_id, department_name "Department", TO_CHAR(NULL) "Warehouse" FROM departments UNION SELECT location_id, TO_CHAR(NULL) "Department", warehouse_name FROM warehouses; LOCATION_ID Department Warehouse ----------- --------------------- -------------------------- 1400 IT 1400 Southlake, Texas 1500 Shipping 1500 San Francisco 1600 New Jersey 1700 Accounting 1700 Administration 1700 Benefits 1700 Construction ...
UNION ALL Example
The
UNIONoperator returns only distinct rows that appear in either result, while the
UNION
ALLoperator returns all rows. The
UNION
ALLoperator does not eliminate duplicate selected rows:
SELECT product_id FROM order_items UNION SELECT product_id FROM inventories; SELECT location_id FROM locations UNION ALL SELECT location_id FROM departments;
A
location_idvalue that appears multiple times in either or both queries (such as '
1700') is returned only once by the
UNIONoperator, but multiple times by the
UNION
ALLoperator.
INTERSECT Example
The following statement combines the results with the
INTERSECToperator, which returns only those rows returned by both queries:
SELECT product_id FROM inventories INTERSECT SELECT product_id FROM order_items;
MINUS Example
The following statement combines results with the
MINUSoperator, which returns only rows returned by the first query but not by the second:
SELECT product_id FROM inventories MINUS SELECT product_id FROM order_items;
相关文章推荐
- C++---前向声明应用注意
- 带有加解密通信的应用安装为windows服务时,需要注意使用的账户
- MOSFET选型注意事项及应用实例
- Unity3D 移动应用与C#开发注意事项(不定时更新)
- 网页制作中注意应用html标签的问题
- android应用性能优化注意点
- 做移动应用使用地图API时需要注意的问题
- 内存和对象内存池技术在网游开发中的注意点和应用zz
- c#编写高性能Tcp Socket应用注意事项
- React-router在混合应用开发中的注意事项。
- pgsql数据库应用两点注意
- 电视的应用开发注意事项[持续更新]
- iOS应用内支付(IAP)的注意事项
- Gabor金字塔在视觉注意模型研究中的应用(三)--冲刺篇
- LoadRunner特殊函数应用注意事项
- JAVA应用AES/DES算法时需要注意的地方
- Asp.net中Split函数的应用及注意事项。
- Appium测试混合应用失败后截图注意事项
- Mater-Details数据查询修改时,在用DetailsView进行新建,编辑(添加DropDownList控件)应用时需要注意的几点问题
- FLEX RSL 应用注意事项