The following code is marked with
This function should be refactored so that its last statement is a RETURN one. sonarlint(plsql:FunctionLastStatementReturnCheck)
CREATE FUNCTION test_case RETURN PLS_INTEGER AS
BEGIN
CASE WHEN 1<2 THEN
RETURN 1;
ELSE
RETURN 0;
END CASE;
END test_case;
While the last statement is not RETURN
, the CASE
statement has an ELSE
block, so the function will always return.
It works as expected with IF
statements (no false positive):
CREATE FUNCTION test_if RETURN PLS_INTEGER AS
BEGIN
IF 1<2 THEN
RETURN 1;
ELSE
RETURN 0;
END IF;
END test_if;
- Rule: plsql:FunctionLastStatementReturnCheck
- Language: Oracle PL/SQL
- SonarQube 9.9.1