【发布时间】:2015-11-22 06:16:01
【问题描述】:
我有下面的代码来显示我在存储过程中“试图”完成的事情:
select * from
(
select to_char(sum(aa.amount))
from additional_amount aa, status st
where aa.int_tran_id = st.int_tran_id
and st.stage in ('ACHPayment_Confirmed')
and aa.entry_timestamp > (
select to_date(trunc(last_day(add_months(sysdate,-1))+1), 'DD-MON-RR') AS "day 1"
from dual
)
)
UNION ALL
(
select distinct it.debit_acct as "debit_accounts"
from internal_transactions it
where it.debit_acct IN ( select texe_cnasupro
from service.kndtexe, service.kndtctc
where texe_cncclipu = tctc_cncclipu
and tctc_cntipcli = 'C'
)
)
union all
(select distinct it.credit_acct as "credit_account"
from internal_transactions it
where it.credit_acct IN (select texe_cnasupro
from service.kndtexe, service.kndtctc
where texe_cncclipu = tctc_cncclipu
and tctc_cntipcli = 'C'
)
)
;
输出:
TO_CHAR(SUM(AA.AMOUNT))
----------------------------------------
130250292.22
6710654504
0000050334
2535814905
0007049560
5 rows selected
输出的第一行是我在 SP 中需要的输出,基于以下两个查询,我猜这两个查询需要针对顶部选择语句进行子查询。
顶部选择是选择一个表与另一个表的连接量之和进行过滤(输出:130250292.22)。
第二个和第三个选择实际上是检查 internal_transactions 表中的帐户是否注册了服务 db 中的相应两个表,这是同一服务器上的不同数据库(由同一应用程序拥有)。
“服务”数据库中的表没有与针对同一数据库的第一个选择中相同的公共主键。
感谢您的帮助!
【问题讨论】:
-
在另一个数据库上创建数据库链接,并将数据库链接和表的访问权限授予第一个数据库模式。
-
我可以从 SP 所在的第一个数据库访问第二个数据库中的表。我正在访问“服务”。在第二个数据库的代码中。
标签: sql oracle stored-procedures plsql