ORACLE多表查詢更新問題

來源:互聯網
上載者:User

由於串連查詢時可能會出現一條對應多條的情況:

如A表與B表串連查詢,A.id有可能對應B.id多個結果,如果這樣寫:

update

(

     select A.id as var,B.id as value

    from A,B where A.key = B.nokey

)

set var=value;

如果在B表的nokey欄位上建一個唯一索引,我猜想應該能行(有時間下去試試)

不多說了,這裡給我實際工作中用到的一個例子:

 update
 (select
          /*+ BYPASS_UJVC */     --跳過檢查(使用這個就可跳過檢查)
        FP.PContractNo as PContractNo,  --合約號
  BC.SerialNo as ContractNo,
  FP.PCertID as PCertID,   --證件號
  CI.CertID as CertID,
  FP.PLoanType as PLoanType,   --貸款類型(業務品種)
  BC.BusinessType as LoanType,
  CR.ObjectNo as ObjectNo,
  FP.PRepayDate as PRepayDate,  --扣款日期
  BC.MonRepayDay as RepayDate,       
  FP.PInstmentType as PInstmentType,  --扣款類型
  BC.ReturnPeriod as InstmentType
 from FUND_PRETREAT FP,BUSINESS_CONTRACT BC,CONTRACT_RELATIVE CR,CUSTOMER_INFO CI
 where  FP.ContractNo = BC.SerialNo
   and BC.SerialNo = CR.ObjectNo
   and CR.ObjectType = 'AF'
   and BC.CustomerID = CI.CustomerID
   and BC.InputOrgId in (select BelongOrgId from Org_Belong where OrgId = '?')
)
 set PContractNo = ContractNo,
  PCertID = CertID,
  PLoanType = decode(ObjectNo,null,decode(LoanType,'91','01','92','01','02'),decode(LoanType,'91','03','92','03','04')),
  PRepayDate = RepayDate,
  PInstmentType = InstmentType

 

當然你得保證一個更新的欄位是一對一的,否則說不定會出現什麼問題。
      
   

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.