Home

Strings should only be moved to variables or columns which are large enough to hold them

Rule description

  • Strings should only be moved to variables or columns which are large enough to hold them

 

Non-compliant Code Example

CREATE TABLE CUSTOMERDETAILS (id number, first_name varchar2(30),landmark varchar2);

INSERT INTO CUSTOMERDETAILS (id, first_name, landmark) VALUES (1, 'Alice', 'Near H P Hospital'); 

CREATE OR REPLACE PROCEDURE GetCustomerName
IS
  customerName varchar2(15);
BEGIN
	SELECT first_name into customerName from CUSTOMERDETAILS where Id = 152; --Non compliant code (first_name column is of length 30 and tried to assign variable customerName of length 15)
END;

PROCEDURE UpdateCustomerName(id_v in number, first_name_v in nvarchar2(75), landmark_v in nvarchar2)
IS
BEGIN
    UPDATE CUSTOMERDETAILS
    SET first_name=first_name_v, landmark=landmark_v --Non compliant code (first_name_v is variable is of length 75 and tried to assign to column first_name of length 30)
    WHERE Id = id_v;
END UpdateCustomerName;
Visual Expert 2020
 VEPLSQLRULE51