SQL (+)= 定义和函数

标签 sql oracle outer-join

我想知道 SQL 中的这条语句实际上做了什么:

select * 
from table 
where A (+)= B

我反对:
select * 
from table 
where A = B

并看到了差异,但不知道如何解释 (+)=' 的功能是什么。在我看来, (+)= 告诉它在可用时使其满足条件 A = B,如果组件不可用,则忽略/输入为“空”。

此外,此语句在 create view 语句中运行。

提前致谢。

最佳答案

(+)= 用于显示 外连接 .现在不用了,是已弃用 现在(因为它不是很可读)。 (+) 表示 JOIN 中的“可选”表。我也认为 +表示法只是为了向后兼容而存在,因为 Oracle 在 ANSI 连接标准实现之前就推出了它。

Also note that 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:

-- The following statement is not valid:
     SELECT employee_id, manager_id 
    FROM employees
    WHERE employees.manager_id(+) = employees.employee_id;

但是,以下自联接是有效的:
   SELECT e1.employee_id, e1.manager_id, e2.employee_id
    FROM employees e1, employees e2
    WHERE e1.manager_id(+) = e2.employee_id
    ORDER BY e1.employee_id, 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.

关于SQL (+)= 定义和函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21981572/

相关文章:

php - 您的 SQL 语法有错误;检查手册以了解在 'AND ` user_id` = 1' 附近使用的正确语法

java - 无法使用以下凭据连接到数据库 :jdbc:oracle:thin@:smthing

sql - Oracle sql 不同查询

hibernate - (Lazy) LEFT OUTER JOIN 使用 Hibernate Criteria API

mysql - 在MySQL中指定 'Full Outer Join'条件的目的是什么?

sql - SQL CLR 触发器可以做到这一点吗?或者,还有更好的方法?

sql - 我可以使用索引优化包含 WHERE Value <> 2 的请求吗

PHP Mysql 提交表单

java - 获取 java.sql.SQLSyntaxErrorException : ORA-00936: missing expression error

mysql - 使用LEFT JOIN的MySQL查询不会返回空结果