2
IF((SELECT COUNT(*) FROM IPA_PRCADJ_HDR WHERE TRM_CODE = 41) = 0)
THEN
  select '111111' from dual;
ELSE
 SELECT '0000000' FROM DUAL;
END IF;

showing error..

Error starting at line 73 in command:

END IF
ERROR REPORT:
Unknown Command

2 Answers 2

6

You can't build conditions like this. Try to build them inside the select statement like this:

select case
       when exists
            ( select 1
              from   IPA_PRCADJ_HDR
              where  TRM_CODE = 41
            )
       then '111111'
       else '0000000'
       end
from   dual
Sign up to request clarification or add additional context in comments.

1 Comment

The query was incorrect as the "select 1 from..." statement yielded no results when the table was empty.
0

This takes into account the scenario when the table is empty.

SELECT CASE WHEN MAX(TRM_CODE) IS NULL THEN 'FALSE' ELSE 'TRUE' END FROM (SELECT * FROM IPA_PRCADJ_HDR WHERE TRM_CODE = 41)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.