2016-10-10 195 views
0

我在創建下面的過程時遇到了以下錯誤,我也從過程中刪除了大部分部分,僅包含了我正面臨的部分問題。問題在解碼條款中,請幫助!編譯過程時出現oracle錯誤

[警告] ORA-24344:成功與編譯錯誤41分之84PL/SQL: ORA-00907:錯過右括號四分之三十三PL/SQL:SQL語句 忽略(2:0):警告:編譯但編譯錯誤

CREATE OR REPLACE PROCEDURE ERR_OUT (
    in_Srcsyscd     IN  VARCHAR2) 
IS 
    rcrdnums VARCHAR2 (32767); 
    rcrd_cnt INT; 
BEGIN 
    rcrd_cnt := 500; 

    SELECT RTRIM (
      XMLCAST (
       XMLAGG (XMLELEMENT (e, RCRDNUM) ORDER BY RCRDNUM) AS CLOB), 
      ',') 
    INTO rcrdnums 
    FROM (SELECT (ERR.RCRDNUM || ',') AS RCRDNUM 
      FROM tableName ERR 
        WHERE  ROWNUM <= rcrd_cnt 
        AND ( in_srcsyscd IS NULL 
         OR (decode (REGEXP_COUNT (in_srcsyscd, ','),0,(ERR.Srcsyscd = in_srcsyscd),        
           (ERR.Srcsyscd IN 
            (SELECT DISTINCT srcsyscd 
             FROM tableName 
             WHERE srcsyscd IN 
                (SELECT err.srcsyscd 
                FROM tableName ERR 
                  RIGHT OUTER JOIN 
                  ( SELECT UPPER (
                     REGEXP_SUBSTR (
                      in_Srcsyscd, 
                      '[^,]+', 
                      1, 
                      LEVEL)) 
                     CNTRY_CD 
                   FROM DUAL 
                  CONNECT BY REGEXP_SUBSTR (in_Srcsyscd, 
                     '[^,]+', 
                     1, 
                     LEVEL) 
                     IS NOT NULL) CNTRY_P 
                  ON (UPPER (
                    ERR.srcsyscd) != 
                    CNTRY_P.CNTRY_CD)) 
              OR srcsyscd IS NULL))))) 

下面是我現在所面臨的問題,並沒有與括號的數量沒有問題,我可以觀察,但仍甲骨文拋出錯誤此where子句:

AND ( in_srcsyscd IS NULL 
         OR (decode (REGEXP_COUNT (in_srcsyscd, ','),0,(ERR.Srcsyscd = in_srcsyscd),        
           (ERR.Srcsyscd IN 
            (SELECT DISTINCT srcsyscd 
             FROM AMT_OWNER.AMT_EVNT_SPND_ERR_STG 
             WHERE srcsyscd IN 
                (SELECT err.srcsyscd 
                FROM TableName 
                  RIGHT OUTER JOIN 
                  ( SELECT UPPER (
                     REGEXP_SUBSTR (
                      'CONCUR', 
                      '[^,]+', 
                      1, 
                      LEVEL)) 
                     CNTRY_CD 
                   FROM DUAL 
                  CONNECT BY REGEXP_SUBSTR (
                     'CONCUR', 
                     '[^,]+', 
                     1, 
                     LEVEL) 
                     IS NOT NULL) CNTRY_P 
                  ON (UPPER (
                    ERR.srcsyscd) != 
                    CNTRY_P.CNTRY_CD)) 
              OR srcsyscd IS NULL))))) 
+0

「缺少右括號」給你所有。如果您使用記事本++或一些括號的幫助,你會發現你錯過了最後一個圓括號 ...「或srcsyscd IS NULL)))))」 –

+1

這似乎不是一個括號的問題。 –

回答

0

解碼中的複雜語句在語法上不正確。 你不能寫:

decode(a,b,c,(err.srcsyscd in ...)) 

我建議你用case語句替換解碼。邏輯將更清晰地閱讀和維護。

例(不知道這是正確的邏輯你)

where rownum <= rcrd_cnt 
    and (case 
      when in_srcsyscd is null then 
      1 
      else 
      when regexp_count(in_srcsyscd, ',') = 0 then 
      case 
       when err.srcsyscd = in_srcsyscd then 
       1 
       else 
       0 
      end 
      else 
      when err.srcsyscd in 
       (select distinct srcsyscd 
        from tablename 
       where srcsyscd in 
         (select err.srcsyscd 
          from tablename err 
         right outer join (select upper(regexp_substr(in_srcsyscd, '[^,]+', 1, level)) cntry_cd 
              from dual 
              connect by regexp_substr(in_srcsyscd, '[^,]+', 1, level) is not null) cntry_p 
          on (upper(err.srcsyscd) != cntry_p.cntry_cd)) 
        or srcsyscd is null) then 
      1 
      else 
      0 
     end) = 1 
+0

請問您可以寫上面的邏輯用例 –