有没有办法使用合并语句将此查询转换为 Oracle 查询?

Posted

技术标签:

【中文标题】有没有办法使用合并语句将此查询转换为 Oracle 查询?【英文标题】:Is there a way to convert this query into Oracle query using merge statement? 【发布时间】:2020-10-22 05:39:39 【问题描述】:
   Update
   vtnhmashaupl as UPL 
   inner join
      vtsmvaccounts vacc 
      on vaccines. Vaiban = upl.vaiban 
   Inner join
      vtsmvaccfmrmap as vfmr 
      on vacc.vaibanid = vfmr.vaibanid 
      and vfmr.fmrcode = upl.fmrcode 
   inner join
      vtnhmbudget bd 
      on bd.hloccode = vacc.vacustidnt 
   inner join
      vtnhmbudgetdtls dtls 
      on dtls.fmrcode = upl.fmrcode 
      and ifnull (Dtls.fnyear, bd.fnyear) = in_fnyear 
set
   upl.buddtlsid = dtls.buddtlsid, upl.budid = dtls.budid, upl.hloccode = bd.hloccode;

【问题讨论】:

【参考方案1】:

我认为这符合您的期望。如果没有表结构和示例输入数据,我无法对其进行测试。

merge into vtnhmashaupl upl
using ( select vacc.vaiban
               , vfmr.fmrcode
               , dtls.buddtlsid
               , dtls.budid
               , bd.hloccode
        from vtsmvaccounts vacc 
        inner join vtsmvaccfmrmap as vfmr 
          on vacc.vaibanid = vfmr.vaibanid 
        inner join vtnhmbudget bd 
          on bd.hloccode = vacc.vacustidnt 
        inner join vtnhmbudgetdtls dtls 
          on dtls.fmrcode = vfmr.fmrcode
          and nvl (dtls.fnyear, bd.fnyear) = in_fnyear 
       ) sq
on ( sq.vaiban  = upl.vaiban  
     and sq.fmrcode = upl.fmrcode )         
when matched then 
    update          
    set upl.buddtlsid = sq.buddtlsid
       , upl.budid = sq.budid
       , upl.hloccode = sq.hloccode;

【讨论】:

谢谢。真的很有帮助

以上是关于有没有办法使用合并语句将此查询转换为 Oracle 查询?的主要内容,如果未能解决你的问题,请参考以下文章

有没有办法将此插入合并到选择查询中?

如何将此代码转换为准备好的语句或 jdbc 中的语句? [关闭]

将 Oracle 合并查询转换为 mysql mySQL 查询

如何将此 SQL 内部联接查询转换为 LINQ 语法?

oracle中的update语句能用相关子查询么?

求助,oracle多行数据合并成一行