SQL 查询中 (+) 的含义

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/517557/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-01 01:02:33  来源:igfitidea点击:

Meaning of (+) in SQL queries

sqloracle

提问by Zabbala

I've come across some SQL queries in Oracle that contain '(+)' and I have no idea what that means. Can someone explain its purpose or provide some examples of its use? Thanks

我在 Oracle 中遇到过一些包含“(+)”的 SQL 查询,但我不知道这意味着什么。有人可以解释其目的或提供一些使用示例吗?谢谢

回答by Quassnoi

It's Oracle's synonym for OUTER JOIN.

它是 Oracle 的同义词OUTER JOIN

SELECT *
FROM a, b
WHERE b.id(+) = a.id

gives same result as

给出相同的结果

SELECT *
FROM a
     LEFT OUTER JOIN b
     ON b.id = a.id

回答by Geoff

The + is a short cut for OUTER JOIN, depending on which side you put it on, it indicates a LEFT or RIGHT OUTER JOIN

+ 是 OUTER JOIN 的快捷方式,取决于你把它放在哪一边,它表示 LEFT 或 RIGHT OUTER JOIN

Check the second entry in this forum postfor some examples

检查此论坛帖子中的第二个条目以获取一些示例

回答by Harper Shelby

IIRC, the + is used in older versions of Oracle to indicate an outer join in the pre-ANSI SQL join syntax. In other words:

IIRC,在旧版本的 Oracle 中使用 + 来指示预 ANSI SQL 连接语法中的外部连接。换句话说:

select foo,bar
from a, b
where a.id = b.id+

is the equivalent of

相当于

select foo,bar
from a left outer join b
on a.id = b.id

NOTE: this may be backwards/slightly incorrect, as I've never used the pre-ANSI SQL syntax.

注意:这可能是倒退/稍微不正确,因为我从未使用过 ANSI 之前的 SQL 语法。

回答by Cory House

You use this to assure that the table you're joining doesn't reduce the amount of records returned. So it's handy when you're joining to a table that may not have a record for every key you're joining on.

您使用它来确保您加入的表不会减少返回的记录数量。因此,当您加入一个可能没有您加入的每个键的记录的表时,这很方便。

For example, if you were joining a Customer and Purchase table:

例如,如果您要加入 Customer 和 Purchase 表:

To list of allcustomers and all their purchases, you want to do an outer join (+) on the Purchase table so customers that haven't purchased anything still show up in your report.

要列出所有客户及其所有购买,您需要在购买表上执行外连接 (+),以便尚未购买任何产品的客户仍显示在您的报告中。