我正在输入一个函数,我在这里遇到错误,我不知道它是什么。你能帮我一把吗?
CREATE or replace FUNCTION function1(pIdReg in number,pIdPeriod in number) RETURN
number
IS
ncv number DEFAULT 0;
BEGIN
SELECT COUNT(IdPeriod)
INTO ncv
FROM(
SELECT a.IdPeriod, SUM(case when a.nt=0 then -a.valor else a.valor end) AS total --IF(a.nt=0,-a.valor,a.valor))
FROM dc a
JOIN emp b ON a.idDoc = b.idDoc
WHERE a.idReg = pIdReg AND a.IdPeriod < pIdPeriod AND
b.cc != 305 AND
(
b.cc = 302 AND(b.tipomov != 4)
OR
b.cc != 302 AND(1=1)-- emular el TRUE
)
AND a.type != 7
GROUP BY 1 HAVING total != 0
) AS ncv;
RETURN ncv;
END;
/
错误是 SQL 命令未正确结束。Sqldeveloper 显示“AS ncv”下划线。group by 或有子句有什么问题吗?