G-1050: Avoid using literals in your code.

Minor

Changeability

Reason

Literals are often used more than once in your code. Having them defined as a constant reduces typos in your code and improves the maintainability.

All constants should be collated in just one package used as a library. If these constants should be used in SQL too it is good practice to write a deterministic package function for every constant.

Example (bad)

DECLARE
   l_job employees.job_id%TYPE;
BEGIN
   SELECT e.job_id
     INTO l_job
     FROM employees e
    WHERE e.manager_id IS NULL;

   IF l_job = 'AD_PRES' THEN
      NULL;
   END IF;
EXCEPTION
   WHEN NO_DATA_FOUND THEN 
      NULL; -- handle_no_data_found;
   WHEN TOO_MANY_ROWS THEN 
      NULL; -- handle_too_many_rows; 
END;
/

Example (good)

CREATE OR REPLACE PACKAGE constants_up IS
   co_president CONSTANT employees.job_id%TYPE := 'AD_PRES';
END constants_up;
/

DECLARE
   l_job employees.job_id%TYPE;
BEGIN
   SELECT e.job_id
     INTO l_job
     FROM employees e
    WHERE e.manager_id IS NULL;

   IF l_job = constants_up.co_president THEN
      NULL;
   END IF;
EXCEPTION
   WHEN NO_DATA_FOUND THEN 
      NULL; -- handle_no_data_found;
   WHEN TOO_MANY_ROWS THEN 
      NULL; -- handle_too_many_rows; 
END;
/