Home

Uninitialized NOT NULL Variables

Description

    The Uninitialized NOT NULL Variables rule states that all NOT NULL variables must be initialized before use. This rule ensures that all variables are properly initialized and that the code does not attempt to use a variable that has not been initialized. This rule helps to prevent errors and unexpected behavior in the code. It also helps to ensure that the code is more readable and maintainable.

Key Benefits

  • Ensures Data Integrity: Initialized NOT NULL variables ensure that data integrity is maintained by preventing the insertion of invalid data into the database.
  • Reduces Development Time: Initialized NOT NULL variables reduce development time by eliminating the need to manually check for invalid data.
  • Improves Performance: Initialized NOT NULL variables improve performance by eliminating the need to check for invalid data at runtime.

 

Non-compliant Code Example

DECLARE 
    firstname CUSTOMERS.FIRSTNAME % TYPE NOT NULL;
    lastname CUSTOMERS.LASTNAME % TYPE;
    landmark CUSTOMERS.LANDMARK % TYPE NOT NULL;            --Non compliant code(NOT NULL variables is not initialized)

BEGIN
    SELECT FIRSTNAME, LASTNAME, LANDMARK
    INTO firstname, lastname
    FROM CUSTOMERS

    WHERE(CREDIT_LIMIT = 1800 AND CREDIT_LIMIT > 1100);
            END; 

Compliant Code Example

DECLARE 
    firstname CUSTOMERS.FIRSTNAME % TYPE NOT NULL;
    lastname CUSTOMERS.LASTNAME % TYPE;
    landmark CUSTOMERS.LANDMARK % TYPE NOT NULL;            --Compliant code(NOT NULL variables is initialized)

BEGIN
    SELECT FIRSTNAME, LASTNAME, LANDMARK
    INTO firstname, lastname, landmark
    FROM CUSTOMERS

    WHERE(CREDIT_LIMIT = 1800 AND CREDIT_LIMIT > 1100);
            END; 
Visual Expert 2024
 VEPLSQLRULE7