Home

Functions and procedures should not have too many parameters

Description

    The rule "Functions and procedures should not have too many parameters" is an important one to follow when writing PL/SQL code. Having too many parameters can make the code difficult to read and maintain, and can lead to errors. It is best to limit the number of parameters to only the ones that are absolutely necessary. Additionally, it is important to ensure that all parameters are properly documented so that other developers can understand their purpose and use. Finally, it is important to ensure that all parameters are properly validated to ensure that the code is secure and reliable. Following these guidelines will help ensure that your PL/SQL code is well-structured and maintainable.

Key Benefits

  • Reduced complexity: Functions and procedures with fewer parameters are easier to understand and maintain.
  • Easier debugging: Fewer parameters make it easier to identify and debug errors.
  • Improved readability: Functions and procedures with fewer parameters are easier to read and understand.
  • Increased reusability: Functions and procedures with fewer parameters are more likely to be reused.

 

Non-compliant Code Example

function GetCompleteCustomerDetails(FirstName in nvarchar2, --Non compliant code (Function with more the default 10 number of parameters)
LastName in nvarchar2,
ADDRESS1 in nvarchar2,
ADDRESS2 in nvarchar2,
Area in nvarchar2,
City in nvarchar2,
State in nvarchar2,
Country in nvarchar2,
Landmark in nvarchar2,
Pincode in nvarchar2,
ContactNumber in nvarchar2,
Email in nvarchar2) return nvarchar2 
IS
BEGIN
	RETURN CONCAT(FirstName , LastName , ADDRESS1 , ADDRESS2 , Area , City , State , Country , Landmark , Pincode ,ContactNumber , Email);
	
END GetCompleteCustomerDetails

Compliant Code Example

CREATE OR REPLACE TYPE EMP_T AS OBJECT
(
	    FirstName  VARCHAR2(30),
        LastName  VARCHAR2(30),
	    ADDRESS1  VARCHAR2(30),
	    ADDRESS2  VARCHAR2(30),
	    Area  VARCHAR2(30),
	    City  VARCHAR2(30),
	    State  VARCHAR2(30),
	    Country  VARCHAR2(30),
	    Landmark  VARCHAR2(30),
	    Pincode  VARCHAR2(30),
	    ContactNumber  VARCHAR2(30),
	    Email  VARCHAR2(30)
);
/

CREATE OR REPLACE TYPE EmpType AS TABLE OF EMP_T;
/

function GetCompleteCustomerDetails(emp_clbk IN EmpType) return VARCHAR2 --Compliant code
IS
cnt pls_integer;
BEGIN

    cnt := emp_clbk.first;

    RETURN CONCAT(emp_clbk(cnt).FirstName, emp_clbk(cnt).LastName);

END GetCompleteCustomerDetails;
Visual Expert 2024
 VEPLSQLRULE105