ORA-01427 單行子查詢返回多於一個行 - 20190130

報錯前:

select  
   (select m.contract_subid
           from xs.T_S_CONTRACT_D m
         where m.seg_no = d.seg_no
            and m.contract_subid = d.contract_subid) "dd_contract_subid"
       ,(select m.spec
           from xs.T_S_CONTRACT_D m
         where m.seg_no = d.seg_no
            and m.contract_id = d.contract_id) "dd_spec"
  from xs.T_S_SETTLE_M a, xs.t_s_settle_d d
  where 1=1
    and a.seg_no = d.seg_no
    and a.settle_id = d.settle_id

修改後:

  select  
   (select m.contract_subid
           from xs.T_S_CONTRACT_D m
         where m.seg_no = d.seg_no
            and m.contract_id = d.contract_id
            and m.contract_subid = d.contract_subid) "dd_contract_subid"
       ,(select m.spec
           from xs.T_S_CONTRACT_D m
         where m.seg_no = d.seg_no
            and m.contract_id = d.contract_id
            and m.contract_id = d.contract_id) "dd_spec"
  from xs.T_S_SETTLE_M a, xs.t_s_settle_d d
  where 1=1
    and a.seg_no = d.seg_no
    and a.settle_id = d.settle_id

因爲xs.T_S_CONTRACT_D和 xs.t_s_settle_d 都是子表,直接用 '合同號' 關聯自然就出現都行信息,所以在加上一個 '合同子項號' 就沒問題了

子查詢注意你加的關聯條件,避免不存在的問題

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章