我在创建以下程序时遇到以下错误,我还从程序中删除了大部分部分,并且仅包括我面临问题的部分。问题在解码条款中,请帮忙!!!
[警告] ORA-24344:成功编译错误84/41 PL / SQL: ORA-00907:缺少右括号33/4 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子句我面临的问题,我可以观察到的括号数没有问题,但是oracle仍然为此抛出错误:
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 :(得分: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