[英]How to update table rows with values from a table join in oracle
I need to update a table (table 1) with values obtained from joining table 1 with table 2我需要使用从表 1 与表 2 连接获得的值更新表(表 1)
I was able to achieve this in SQL Server:我能够在 SQL Server 中实现这一点:
UPDATE loanacct_payment_history SET paid_by_cifno=loanacct.cifno FROM loanacct_payment_history INNER JOIN loanacct ON loanacct_payment_history.acctrefno=loanacct.acctrefno
the above SQL works perfectly in SQL Server, but doesn't run in Oracle.上述 SQL 在 SQL Server 中完美运行,但不能在 Oracle 中运行。
I tried the following in Oracle but it's not working:我在 Oracle 中尝试了以下操作,但它不起作用:
UPDATE loanacct_payment_history LAPH SET (paid_by_cifno) = (SELECT LA.cifno FROM loanacct LA WHERE LA.acctrefno = LAPH.acctrefno) WHERE EXISTS (SELECT LA.cifno FROM loanacct LA WHERE LA.acctrefno = LAPH.acctrefno)
Any help would be greatly appreciated.任何帮助将不胜感激。
What does "not working" mean? “不工作”是什么意思? The following should be syntactically correct in SQL and update what you want: SQL 中的以下内容在语法上应该是正确的,并更新您想要的内容:
UPDATE loanacct_payment_history LAPH
SET paid_by_cifno = (SELECT LA.cifno
FROM loanacct LA
WHERE LA.acctrefno = LAPH.acctrefno
)
WHERE EXISTS (SELECT LA.cifno
FROM loanacct LA
WHERE LA.acctrefno = LAPH.acctrefno
)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.