I am trying to compile this procedure in Oracle 8i:
Getting the following error: PLS-00103: Encountered the symbol "CASE" when expecting one of the following:
Help please.
Code:
CREATE OR REPLACE PROCEDURE Sp_Update_LSAPP_WORKFLOWSTATUS IS
BEGIN
DELETE FROM LSAPP_WORKFLOWSTATUS;
--
INSERT INTO LSAPP_WORKFLOWSTATUS
SELECT DEPARTMENT, DEPTINITIAL,
SUM(CASE WHEN CATG = 'BACKLOG' THEN 1 ELSE 0 END) AS WOB_BACKLOG,
SUM(CASE WHEN CATG = 'BACKLOG' AND CREATETIME < TRUNC(SYSDATE-(SELECT VAR_VALUE FROM LSAPP_VARIABLES WHERE VAR_NAME = 'old_backlog')) THEN 1 ELSE 0 END) AS OLD_BACKLOG,
SUM(CASE WHEN CATG = 'BACKLOG' AND EXISTS (SELECT * FROM REPORTLS.RETAIL_PROCESSLOG C WHERE C.WOBNUM = F_WOBNUM AND (C.STEPNAME = 'Complete' OR C.STEPNAME LIKE '%QA%')) THEN 1 ELSE 0 END) AS WOB_BACKLOG_COMPLETE,
CASE WHEN SUM(CASE WHEN CATG = 'BACKLOG' THEN 1 ELSE 0 END) = 0 THEN 0 ELSE SUM(CASE WHEN CATG = 'BACKLOG' AND CREATETIME < TRUNC(SYSDATE-(SELECT VAR_VALUE FROM LSAPP_VARIABLES WHERE VAR_NAME = 'old_backlog')) THEN 1 ELSE 0 END) / SUM(CASE WHEN CATG = 'BACKLOG' THEN 1 ELSE 0 END) END AS OLD_BACKLOG_PCT,
SUM(CASE WHEN CATG = 'NEW' THEN 1 ELSE 0 END) AS WOB_NEW,
SUM(CASE WHEN CATG = 'NEW' AND EXISTS (SELECT * FROM REPORTLS.RETAIL_PROCESSLOG C WHERE C.WOBNUM = F_WOBNUM AND (C.STEPNAME = 'Complete' OR C.STEPNAME LIKE '%QA%')) THEN 1 ELSE 0 END) AS WOB_NEW_COMPLETE,
CASE WHEN SUM(CASE WHEN CATG = 'NEW' THEN 1 ELSE 0 END) = 0 THEN 0 ELSE SUM(CASE WHEN CATG = 'NEW' AND EXISTS (SELECT * FROM REPORTLS.RETAIL_PROCESSLOG C WHERE C.WOBNUM = F_WOBNUM AND (C.STEPNAME = 'Complete' OR C.STEPNAME LIKE '%QA%')) THEN 1 ELSE 0 END) / SUM(CASE WHEN CATG = 'NEW' THEN 1 ELSE 0 END) END AS NEW_COMPLETE_PCT,
SYSDATE AS LASTUPDATE
FROM (
SELECT WOBNUM AS F_WOBNUM, DEPARTMENT, DEPTINITIAL, 'BACKLOG' AS CATG, CREATETIME
FROM LS_WOBBACKLOG A, REPORTLS.WORKTYPES B
WHERE A.WORKTYPE = B.WORKTYPE
AND ENQUEUETIME < TRUNC(SYSDATE-1)+17/24
UNION ALL
SELECT WOBNUM AS F_WOBNUM, DEPARTMENT, DEPTINITIAL, 'NEW' AS CATG, STARTTIME
FROM REPORTLS.RETAIL_PROCESSLOG A, REPORTLS.WORKTYPES B
WHERE A.WORKTYPE = B.WORKTYPE
AND ENQUEUETIME >= TRUNC(SYSDATE-1)+17/24 AND ENQUEUETIME < TRUNC(SYSDATE)+17/24
AND DEPARTMENT NOT LIKE 'Direct Retail Lending%'
AND USERID NOT IN (SELECT P8USERID FROM REPORTLS.BGPERFORMERS)
AND STEPNAME IN (SELECT STEPNAME FROM REPORTLS.LSAPP_STEPNAME) )
GROUP BY DEPARTMENT, DEPTINITIAL;
COMMIT;
EXCEPTION
WHEN OTHERS THEN
ROLLBACK; -- rollback the transaction
END;
/
Getting the following error: PLS-00103: Encountered the symbol "CASE" when expecting one of the following:
Help please.