Home

Global public variables should not be defined

Rule description

  • Global public variables should not be defined

 

Non-compliant Code Example

CREATE OR REPLACE PACKAGE CUSTOMER_PACKAGE 
IS
 TYPE CUSTOMER_T IS RECORD              --Non compliant code (Global public variable is defined)
	( FirstName VARCHAR2(50),
	  LastName VARCHAR2(50),
	  Area VARCHAR2(100),
	  City VARCHAR2(100));

	function GetCompleteCustomerDetails(customerId In CUSTOMER_T.Id) RETURN CUSTOMER_T;

END CUSTOMER_PACKAGE

Compliant Code Example

CREATE OR REPLACE PACKAGE CUSTOMER_PACKAGE 
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 
IS
 TYPE CUSTOMER_T IS RECORD              --Compliant code (Variable is not defined globally)
	( FirstName VARCHAR2(50),
	  LastName VARCHAR2(50),
	  Area VARCHAR2(100),
	  City VARCHAR2(100));
	  
	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
 VEPLSQLRULE134