1. 程式人生 > >Oracle報錯誤:subquery not allowed in this context 解決方法

Oracle報錯誤:subquery not allowed in this context 解決方法

由於開始編譯時候,一直是報編譯錯誤,同時,顯示錯誤是在Oracle中,查詢if裡面巢狀 in一直顯示不允許子查詢在裡面。

原因:Oracle:IF...IN (SELECT ... FROM ...) 之子查詢不被允許

上程式碼:

if l_chanl_code in (select REF_CDE from IV_WMS_AUTO_PACK_CONF where REF_TYPE = 'CHANL_CODE' and AUTO_PACK_IND = 'N') then
  return 'N';
end if;

這裡一直報錯。無法編譯,那麼更改一下即可成功解決。

解決方法:換一種寫法。這只是其中的一種寫法解決方法,個人還是很嫌棄用in的,因為實在太太太慢了查詢。

上程式碼:

  select third_party_cde into l_chanl_code
    from es_order_line where order_key = v_order_id and rownum = 1 and third_party_cde in(
         select REF_CDE from IV_WMS_AUTO_PACK_CONF where REF_TYPE = 'CHANL_CODE' and AUTO_PACK_IND = 'N'
    ) ;
    if l_chanl_code is not null then
     return 'N';
   -- if l_chanl_code in (select REF_CDE from IV_WMS_AUTO_PACK_CONF where REF_TYPE = 'CHANL_CODE' and AUTO_PACK_IND = 'N') then
    end if;