[英]joining same table multiple times in Oracle
嗨,我正在tuning
一个遗留代码。 我们在一个大查询中有以下 2 个表。
fnd_currencies, and pa_commitment_txns
我在 from 子句中看到了
fnd_currencies fca,
fnd_currencies fcr,
fnd_currencies fcp,
pa_commitment_txns pct
第一个表已被使用三次,并且已与同一个表的同一column
进行外部连接。
AND fca.currency_code(+) = pct.acct_currency_code
AND fcr.currency_code( +) = pct.receipt_currency_code
AND fcp.currency_code(+) = pct.project_currency_code
以上 3 行只能使用fnd_currencies
表处理一次。 有没有更聪明的方法来做到这一点?
您可以使用子查询因式分解子句确保只查询一次fnd_currencies
。 这看起来像这样(并通过使用 ANSI 92 语法让@gordonlinoff 满意):
with ccy as ( select *
from fnd_currencies )
select fca.descr as acct_currency
,fcr.descr as receipt_currency
,fcp.descr as project_currency
,pct.*
from pa_commitment_txns pct
left outer join ccy fca on fca.currency_code = pct.acct_currency_code
left outer join ccy fcr on fcr.currency_code = pct.receipt_currency_code
left outer join ccy fcp on fcp.currency_code = pct.project_currency_code
这是否会真正为您提供改进的执行时间取决于您尚未向我们保证的数据详细信息。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.