Oracle database pl sql syntax error
I am trying to create code that will allow user to enter a QUEUENAME. Then if rows are returned in the select statement enter a record with the results. If there is no records returned I want a record inserted with norows information. When I run the case in Toad there is a syntax error where I have THEN. Can someone help me resolve this syntax error?
SELECT CASE
WHEN EXISTS
(SELECT A.QUEUENAME, DECODE(A.SUBCONSTATUS, 0, 'ERROR', 1, 'NEW', 2, 'STARTED', 3, 'WORKING', 4, 'DONE', 5, 'RETRY', 6, 'TIMEOUT', 7, 'EDITED', 8, 'CANCELED', 9, 'HOLD', A.SUBCONSTATUS) STATUS, TRUNC(LASTUPDDTTM),COUNT() FROM SYSADM.PSAPMSGSUBCON A where A.SUBCONSTATUS in (0,1,2,4) AND A.QUEUENAME = '&QUEUENAME' and TRUNC(LASTUPDDTTM) = TRUNC(SYSDATE) GROUP BY A.QUEUENAME, DECODE(A.SUBCONSTATUS, 0, 'ERROR', 1, 'NEW', 2, 'STARTED', 3, 'WORKING', 4, 'DONE', 5, 'RETRY', 6, 'TIMEOUT', 7, 'EDITED', 8, 'CANCELED', 9, 'HOLD', A.SUBCONSTATUS), TRUNC(LASTUPDDTTM)