Home

Procedures and functions should be encapsulated in packages

Rule description

  • Procedures and functions should be encapsulated in packages

 

Non-compliant Code Example

function GetCompleteCustomerDetails(customerId In INTEGER)     --Non compliant code (Procedures OR functions is not encapsulated in packages)
return CUSTOMER_T 
Is
BEGIN
Select FIRSTNAME,
	LASTNAME,
	AREA,
	CITY 
Into CUSTOMER_T.FirstName,
	CUSTOMER_T.LastName,
	CUSTOMER_T.Area,
	CUSTOMER_T.City 
FROM CUSTOMERS 
Where Id = customerId;
	RETURN CUSTOMER_T; 
END GetCompleteCustomerDetails

Compliant Code Example

CREATE OR REPLACE PACKAGE CUSTOMER_PACKAGE             --Compliant code (Procedures OR functions is encapsulated in packages)
As
	function GetCompleteCustomerDetails(customerId In INTEGER) RETURN CUSTOMER_T;

END CUSTOMER_PACKAGE;

CREATE TYPE CUSTOMER_T AS OBJECT
( FirstName VARCHAR2(50),
  LastName VARCHAR2(50),
  Area VARCHAR2(100),
  City VARCHAR2(100));

CREATE OR REPLACE PACKAGE BODY CUSTOMER_PACKAGE 
AS
	function GetCompleteCustomerDetails(customerId In INTEGER) 
	RETURN CUSTOMER_T 
	Is
	BEGIN
		Select FIRSTNAME,			       
			LASTNAME,
			AREA,
			CITY 
		Into CUSTOMER_T.FirstName,
			CUSTOMER_T.LastName,
			CUSTOMER_T.Area,
			CUSTOMER_T.City 
		FROM CUSTOMERS 
		Where Id = customerId;
	RETURN CUSTOMER_T; 
	END GetCompleteCustomerDetails;
END CUSTOMER_PACKAGE;
Visual Expert 2020
 VEPLSQLRULE76