Home

Functions should end with RETURN statements

Description

    The Pl_Sql code rule that "Functions should end with RETURN statements" states that all functions should be terminated with a RETURN statement. This RETURN statement should be the last line of code in the function and should return a valid value that is compatible with the function's return type. This ensures that the function returns the expected result and does not cause any unexpected errors.

Key Benefits

  • Makes code more readable: Functions that end with return statements make code easier to read and understand, as it clearly indicates the end of the function.
  • Ensures program logic: A function that ends with a return statement ensures that the program logic is followed correctly and that the function does not continue executing after the return statement.
  • Makes debugging easier: Functions that end with return statements make debugging easier, as it is clear where the function ends and the next step begins.
  • Improves code efficiency: Functions that end with return statements can help improve code efficiency, as it prevents unnecessary code from being executed.

 

Non-compliant Code Example

function GetCompleteCustomerDetails(FirstName in nvarchar2,
LastName in nvarchar2,
ADDRESS1 in nvarchar2,
ADDRESS2 in nvarchar2,
Area in nvarchar2,
City in nvarchar2)return nvarchar2    
IS
BEGIN
	RETURN(CONCAT(CONCAT(CONCAT(CONCAT(CONCAT(CONCAT(FirstName,LastName),CONCAT(ADDRESS1,ADDRESS2)),CONCAT(Area,City)))))); 
	
	CONCAT(CONCAT(ADDRESS1,ADDRESS2),CONCAT(Area,City));        --Non compliant code (Functions is not ending with RETURN statements)
	
END GetCompleteCustomerDetails

Compliant Code Example

function GetCompleteCustomerDetails(FirstName in nvarchar2,
LastName in nvarchar2,
ADDRESS1 in nvarchar2,
ADDRESS2 in nvarchar2,
Area in nvarchar2,
City in nvarchar2)return nvarchar2    
IS
BEGIN

	RETURN(CONCAT(CONCAT(CONCAT(CONCAT(CONCAT(CONCAT(FirstName,LastName),CONCAT(ADDRESS1,ADDRESS2)),CONCAT(Area,City))))));  --Compliant code (Functions is ending with RETURN statements)
	
END GetCompleteCustomerDetails
Visual Expert 2024
 VEPLSQLRULE30