Rule: “CASE” expressions should end with “ELSE” clauses (plsql:S131)
Would you mind to replace “expressions” with “statements” in the title of that rule?
The examples are case statements and from what I see I only get issues for case statements, not expressions.
The reason might be that unlike with the CASE statement, no error is raised in the event that no WHEN clause is selected in a CASE expression. Instead, when no WHEN conditions are met, a CASE expression will return NULL.
Here’s an example with a case statement (first) and a case expression (second):
https://dev.finnova.ch/sonar/dashboard?id=sqldeveloper&branch=precommit%2Fuser_lars-20230206-DECLARE salary NUMBER := 20000; employee_id NUMBER := 36325; PROCEDURE give_bonus (emp_id IN NUMBER, bonus_amt IN NUMBER) IS BEGIN DBMS_OUTPUT.PUT_LINE(emp_id); DBMS_OUTPUT.PUT_LINE(bonus_amt); END; BEGIN CASE WHEN salary >= 10000 AND salary <=20000 THEN give_bonus(employee_id, 1500); WHEN salary > 20000 AND salary <= 40000 THEN give_bonus(employee_id, 1000); WHEN salary > 40000 THEN give_bonus(employee_id, 500); END CASE; give_bonus(employee_id, CASE WHEN salary >= 10000 AND salary <= 20000 THEN 1500 WHEN salary > 20000 AND salary <= 40000 THEN 1000 WHEN salary > 40000 THEN 500 END); END;