Home

String variables with no Size specification

Description

    When declaring string variables with no size specification, the maximum size of the string is determined by the database. The maximum size of the string will depend on the database's configuration and the data type of the string. The maximum size of the string can be determined by querying the database for the maximum length of the data type. For example, if the string is of type VARCHAR2, the maximum size of the string can be determined by querying the database for the maximum length of VARCHAR2.

Key Benefits

  • Fixed Size: Declare String variables with fixed size specification allows for more efficient memory usage by limiting the size of the string.
  • Efficient Memory Usage: By limiting the size of the string, it helps to reduce the amount of memory used for storage and processing.
  • Reduced Processing Time: By limiting the size of the string, it helps to reduce the amount of time needed to process the data.

 

Non-compliant Code Example

DECLARE
   first_name varchar2;         --Non compliant code (Column declare of varchar2 without size)
   customer_id INTEGER;
BEGIN
	UPDATE CUSTOMERS 
	SET FIRSTNAME = first_name
	WHERE Id = customer_id;
END;

Compliant Code Example

DECLARE
   first_name varchar2(25);         --Compliant code (Column declare of varchar2 with size)
   customer_id INTEGER;
BEGIN
	UPDATE CUSTOMERS 
	SET FIRSTNAME = first_name
	WHERE Id = customer_id;
END;
Visual Expert 2024
 VEPLSQLRULE5