Home
Procedures should not contain RETURN statements
Description
The rule that "Procedures should not contain RETURN statements" is an important one for PL/SQL code. This rule ensures that the procedure will always execute completely, regardless of the number of times it is called. A RETURN statement will cause the procedure to exit immediately, which can lead to unexpected results. Additionally, a RETURN statement can make it difficult to debug the procedure, as the code will not be executed in its entirety. By avoiding the use of RETURN statements in procedures, developers can ensure that the code will always execute as expected.
Key Benefits
- Improved readability: Procedures without RETURN statements are easier to read and understand, as the code is not cluttered with unnecessary returns.
- Easier debugging: Without RETURN statements, debugging is simpler, as there is no need to trace the flow of control through the procedure.
- Better code reuse: Procedures without RETURN statements can be used in multiple contexts, as they do not rely on specific return values.
Non-compliant Code Example
procedure DeleteCloneCustomer(customerName In varchar2)
As
BEGIN
DELETE CloneCustomer Where Name = customerName;
RETURN; --Non compliant code (Procedure containing return statement)
END DeleteCloneCustomer
Compliant Code Example
procedure DeleteCloneCustomer(customerName In varchar2)
As
BEGIN
DELETE CloneCustomer Where Name = customerName; --Compliant code
END DeleteCloneCustomer