Home

Variables should not be initialized with NULL

Rule description

  • Variables should not be initialized with NULL

 

Non-compliant Code Example

CREATE FUNCTION GetCustomers(cust CUSTOMER_T) RETURN CUSTOMERS_T
PIPELINED IS
  out_cust CUSTOMERS_T := CUSTOMERS_T(NULL);        --Non compliant code (Variable initialized with NULL)
  in_cust cust%ROWTYPE;
BEGIN
  LOOP
    FETCH cust INTO in_cust; 
    EXIT WHEN cust%NOTFOUND;
    
    out_cust.first_name := in_cust.first_name;
    out_cust.last_name := in_cust.last_name;
    out_cust.credit_limit := in_cust.credit_limit;
    PIPE ROW(out_cust);
    
    out_cust.first_name := in_cust.first_name;
    out_cust.last_name := in_cust.last_name;
    out_cust.credit_limit := in_cust.credit_limit;
    PIPE ROW(out_cust);
  END LOOP;
  CLOSE cust;
  RETURN;
END

Compliant Code Example

CREATE FUNCTION GetCustomers(cust CUSTOMER_T) RETURN CUSTOMERS_T
PIPELINED IS
  out_cust CUSTOMERS_T := CUSTOMERS_T();  --Compliant code
  in_cust cust%ROWTYPE;
BEGIN
  LOOP
    FETCH cust INTO in_cust; 
    EXIT WHEN cust%NOTFOUND;
    
    out_cust.first_name := in_cust.first_name;
    out_cust.last_name := in_cust.last_name;
    out_cust.credit_limit := in_cust.credit_limit;
    PIPE ROW(out_cust);
    
    out_cust.first_name := in_cust.first_name;
    out_cust.last_name := in_cust.last_name;
    out_cust.credit_limit := in_cust.credit_limit;
    PIPE ROW(out_cust);
  END LOOP;
  CLOSE cust;
  RETURN;
END
Visual Expert 2020
 VEPLSQLRULE122