Database Oracle SQL查询中的旧式联接

Database Oracle SQL查询中的旧式联接,database,oracle,oracle11g,left-join,oracle-sqldeveloper,Database,Oracle,Oracle11g,Left Join,Oracle Sqldeveloper,我知道这个语法。我知道它很旧,但我正在调整一个旧的查询。我知道下面的语法 emp.deptno(+)=deptno这是右外连接。 但我无法理解下面的意思 和ptm.effective\u start\u date(+)和ptm.effective\u end\u date(+)之间的TRUNC(SYSDATE) (+)是如何在两者之间使用的。它是什么意思?让我们检查一下下面的查询 select tab1.id, tab2.start_date, tab2.end_date from tab1,

我知道这个语法。我知道它很旧,但我正在调整一个旧的查询。我知道下面的语法

emp.deptno(+)=deptno这是右外连接。

但我无法理解下面的意思

和ptm.effective\u start\u date(+)和ptm.effective\u end\u date(+)之间的TRUNC(SYSDATE)


(+)是如何在两者之间使用的。它是什么意思?

让我们检查一下下面的查询

select tab1.id, tab2.start_date, tab2.end_date
from  tab1,
tab2
where tab1.id = tab2.id(+) and
sysdate between tab2.start_date(+) and tab2.end_date(+)
ANSI等效标准为

select tab1.id, tab2.start_date, tab2.end_date
from  tab1 
left outer join tab2
on tab1.id = tab2.id and
sysdate between tab2.start_date  and tab2.end_date
意思是在
ID
上连接,并约束
开始日期
结束日期
,但如果第二个表中没有匹配项,则不要抑制第一个表中的行

样本数据和结果

select * from tab1;

        ID
----------
         1
         2

 select * from tab2;

        ID START_DATE          END_DATE           
---------- ------------------- -------------------
         1 01.01.2020 00:00:00 31.12.2020 00:00:00
连接返回

        ID START_DATE          END_DATE           
---------- ------------------- -------------------
         1 01.01.2020 00:00:00 31.12.2020 00:00:00
         2

让我们检查下面的查询

select tab1.id, tab2.start_date, tab2.end_date
from  tab1,
tab2
where tab1.id = tab2.id(+) and
sysdate between tab2.start_date(+) and tab2.end_date(+)
ANSI等效标准为

select tab1.id, tab2.start_date, tab2.end_date
from  tab1 
left outer join tab2
on tab1.id = tab2.id and
sysdate between tab2.start_date  and tab2.end_date
意思是在
ID
上连接,并约束
开始日期
结束日期
,但如果第二个表中没有匹配项,则不要抑制第一个表中的行

样本数据和结果

select * from tab1;

        ID
----------
         1
         2

 select * from tab2;

        ID START_DATE          END_DATE           
---------- ------------------- -------------------
         1 01.01.2020 00:00:00 31.12.2020 00:00:00
连接返回

        ID START_DATE          END_DATE           
---------- ------------------- -------------------
         1 01.01.2020 00:00:00 31.12.2020 00:00:00
         2

除了在其他答案中有很好的解释外,使用旧语法还有一条黄金法则

规则:

  • 如果有任何条件正在对照任何常量/sys值检查值,则在
    WHERE
    子句中始终使用
    (+)
    符号和外部联接表的列
所以它会是这样的:

Select * from t1 , t2
 Where t1.col = t2.col(+) -- this represent outer join
   And t1.other_col = sysdate -- or some constant -- this is ok as this is main table in join
   And t2.other_col(+) = sysdate -- or some constant -- (+) is needed as it is outer joined table
                                 -- if you will omit (+) here, join will be converted to inner join

除了在其他答案中有很好的解释外,使用旧语法还有一条黄金法则

规则:

  • 如果有任何条件正在对照任何常量/sys值检查值,则在
    WHERE
    子句中始终使用
    (+)
    符号和外部联接表的列
所以它会是这样的:

Select * from t1 , t2
 Where t1.col = t2.col(+) -- this represent outer join
   And t1.other_col = sysdate -- or some constant -- this is ok as this is main table in join
   And t2.other_col(+) = sysdate -- or some constant -- (+) is needed as it is outer joined table
                                 -- if you will omit (+) here, join will be converted to inner join

请阅读手册了解您正在使用的功能。“将外部联接运算符(+)应用于WHERE子句中联接条件中B的所有列”阅读手册了解您正在使用的功能。“将外部联接运算符(+)应用于WHERE子句中联接条件中B的所有列”