如何在Oracle中使用表联接中的值更新表行

时间:2019-06-24 23:41:15

标签: sql oracle plsqldeveloper

我需要使用通过将表1与表2连接而获得的值更新表(表1)

我能够在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

上面的SQL在SQL Server中可以完美地运行,但不能在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)

任何帮助将不胜感激。

1 个答案:

答案 0 :(得分:0)

“无效”是什么意思?以下语法在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
                 )