Home

Magic numbers should not be used

Rule description

  • Magic numbers should not be used

 

Non-compliant Code Example

BEGIN
  FORALL j IN CUSTOMER_TABLE.FIRST..CUSTOMER_TABLE.LAST SAVE EXCEPTIONS
    UPDATE CUSTOMERS SET minimunExpense = 1800      --Non compliant code (Magic numbers is used)
    WHERE 100 < CUSTOMER_TABLE(j);                  --Non compliant code (Magic numbers is used)
 
EXCEPTION
  WHEN OTHERS THEN
    error_message := SQLERRORMSG;
    DBMS_OUTPUT.PUT_LINE (error_message);
    RAISE;
END;

Compliant Code Example

DECLARE 
	minExpenseValue INTEGER := 1800;
	counter INTEGER := 100;

BEGIN
  FORALL j IN CUSTOMER_TABLE.FIRST..CUSTOMER_TABLE.LAST SAVE EXCEPTIONS
    UPDATE CUSTOMERS SET minimunExpense = minExpenseValue      --Compliant code
    WHERE counter < CUSTOMER_TABLE(j);                  --Compliant code
 
EXCEPTION
  WHEN OTHERS THEN
    error_message := SQLERRORMSG;
    DBMS_OUTPUT.PUT_LINE (error_message);
    RAISE;
END;
Visual Expert 2020
 VEPLSQLRULE172