使用 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
clauseOUTER 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 theFROM
clauseOUTER JOIN
syntax:
- You cannot specify the
(+)
operator in a query block that also containsFROM
clause join syntax.- The
(+)
operator can appear only in theWHERE
clause or, in the context of left-correlation (when specifying theTABLE
clause) in theFROM
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 theOR
logical operator.- A
WHERE
condition cannot use theIN
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 toSELECT
for the syntax for an outer join.
关于sql - Oracle 的加号 (+) 表示法和 ansi JOIN 表示法之间的区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1193654/