如何使用来自 table 连接的值更新 table 行
How to update table rows with values from a table join in oracle
我需要用 table 1 与 table 2
连接获得的值更新 table (table 1)
我能够在 SQL 服务器中实现这一点:
UPDATE loanacct_payment_history SET paid_by_cifno=loanacct.cifno FROM loanacct_payment_history INNER JOIN loanacct ON loanacct_payment_history.acctrefno=loanacct.acctrefno
以上 SQL 在 SQL 服务器中完美运行,但在 Oracle 中 运行 不完美。
我在 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)
如有任何帮助,我们将不胜感激。
"not working"是什么意思?以下内容在 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
)
我需要用 table 1 与 table 2
连接获得的值更新 table (table 1)我能够在 SQL 服务器中实现这一点:
UPDATE loanacct_payment_history SET paid_by_cifno=loanacct.cifno FROM loanacct_payment_history INNER JOIN loanacct ON loanacct_payment_history.acctrefno=loanacct.acctrefno
以上 SQL 在 SQL 服务器中完美运行,但在 Oracle 中 运行 不完美。
我在 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)
如有任何帮助,我们将不胜感激。
"not working"是什么意思?以下内容在 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
)