sql - Oracle 的加号 (+) 表示法和 ansi JOIN 表示法之间的区别?

标签 sql performance oracle join

使用 Oracle 的加号表示法 (+) 与 ansi 标准 join 表示法有何区别?

性能有区别吗?

加号是否已弃用?

最佳答案

据我所知,(+) 表示法仅用于向后兼容,因为 Oracle 在 ANSI 连接标准制定之前就首次使用了它。它是 Oracle 特有的,当有等效的符合标准的版本可用时,您应该避免在新代码中使用它。

两者之间似乎存在差异,并且 (+) 表示法具有 ANSI 连接语法所没有的限制。 Oracle 本身建议您不要使用 (+) 表示法。 完整描述位于 Oracle® Database SQL Language Reference 11g Release 1 (11.1) :

Oracle recommends that you use the FROM clause OUTER JOIN syntax rather than the Oracle join operator. Outer join queries that use the Oracle join operator (+) are subject to the following rules and restrictions, which do not apply to the FROM clause OUTER JOIN syntax:

  • You cannot specify the (+) operator in a query block that also contains FROM clause join syntax.
  • The (+) operator can appear only in the WHERE clause or, in the context of left-correlation (when specifying the TABLE clause) in the FROM clause, and can be applied only to a column of a table or view.
  • If A and B are joined by multiple join conditions, then you must use the (+) operator in all of these conditions. If you do not, then Oracle Database will return only the rows resulting from a simple join, but without a warning or error to advise you that you do not have the results of an outer join.
  • The (+) operator does not produce an outer join if you specify one table in the outer query and the other table in an inner query.
  • You cannot use the (+) operator to outer-join a table to itself, although self joins are valid.

For example, the following statement is not valid:

SELECT employee_id, manager_id
FROM employees
WHERE employees.manager_id(+) = employees.employee_id;

However, the following self join is valid:

SELECT e1.employee_id, e1.manager_id, e2.employee_id
FROM employees e1, employees e2
WHERE e1.manager_id(+) = e2.employee_id;
  • The (+) operator can be applied only to a column, not to an arbitrary expression. However, an arbitrary expression can contain one or more columns marked with the (+) operator.
  • A WHERE condition containing the (+) operator cannot be combined with another condition using the OR logical operator.
  • A WHERE condition cannot use the IN comparison condition to compare a column marked with the (+) operator with an expression.

If the WHERE clause contains a condition that compares a column from table B with a constant, then the (+) operator must be applied to the column so that Oracle returns the rows from table A for which it has generated nulls for this column. Otherwise Oracle returns only the results of a simple join.

In a query that performs outer joins of more than two pairs of tables, a single table can be the null-generated table for only one other table. For this reason, you cannot apply the (+) operator to columns of B in the join condition for A and B and the join condition for B and C. Refer to SELECT for the syntax for an outer join.

关于sql - Oracle 的加号 (+) 表示法和 ansi JOIN 表示法之间的区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1193654/

相关文章:

sql - 使用 INTERSECT 的 SELECT 语句

php - 通过 PDO 创建 MySQL 函数时遇到问题

java - IntelliJ 15 CE 的最佳 JVM 设置

sql - Oracle 提示具有多个连接语句的多个索引

mysql - 不使用 LIMIT/ROWNUM/TOP 查询前 5 个结果的 SQL 查询

sql - IN 与 JOIN 大行集

Java + MySQL : Do i have a good way to encrypt a password?

sql - 选择逗号分隔列表项的数量

sql - 如何在Derby中模拟UPDATE x SET(col1,col2)=(SELECT a,b FROM y)?

c++ - 为什么 `std::copy` 在我的测试程序中从 char 缓冲区读取一个 int 比 `memcpy` 慢 5 倍(!)?