Home

NUMBER variables should be declared with precision

Rule description

  • NUMBER variables should be declared with precision

 

Non-compliant Code Example

CREATE OR REPLACE PROCEDURE GetCustomerPhoneNumber (customerId IN INTEGER)
IS
 oracleQuery  VARCHAR2(100);
 customerPhoneNumber NUMBER;             --Non compliant code (NUMBER variable declared without precision)
 
BEGIN
 oracleQuery :=    q'{SELECT PhoneNumber FROM Customers }'
         ||    q'{WHERE id = '}'
         ||    customerId
         ||    q'{'}';
 EXECUTE IMMEDIATE oracleQuery INTO customerPhoneNumber;
END;

Compliant Code Example

CREATE OR REPLACE PROCEDURE GetCustomerPhoneNumber (customerId IN INTEGER)
IS
 oracleQuery  VARCHAR2(100);
 customerPhoneNumber NUMBER(10);         --Compliant code (NUMBER variable declared with precision)
 
BEGIN
 oracleQuery :=    q'{SELECT PhoneNumber FROM Customers }'
         ||    q'{WHERE id = '}'
         ||    customerId
         ||    q'{'}';
 EXECUTE IMMEDIATE oracleQuery INTO customerPhoneNumber;
END;
Visual Expert 2020
 VEPLSQLRULE155