rspec/rules/S2466/plsql/rule.adoc

31 lines
713 B
Plaintext
Raw Normal View History

2021-04-28 16:49:39 +02:00
Always having a ``++RETURN++`` as the last statement in a function is a good practice as it prevents the ``++ORA-06503 PL/SQL: Function returned without value++`` error.
== Noncompliant Code Example
----
CREATE FUNCTION incorrectFunction RETURN PLS_INTEGER IS -- Non-Compliant
BEGIN
NULL; -- This function was expected to return a PLS_INTEGER, but did not. Will lead to ORA-06503
END;
/
BEGIN
DBMS_OUTPUT.PUT_LINE('Ret = ' || incorrectFunction2); -- ORA-06503 PL/SQL: Function returned without value
END;
/
DROP FUNCTION incorrectFunction;
----
== Compliant Solution
----
CREATE FUNCTION correctFunction RETURN PLS_INTEGER IS -- Compliant
BEGIN
RETURN 42;
END;
/
DROP FUNCTION correctFunction;
----