G-2220: Try to use PLS_INTEGER instead of NUMBER for arithmetic operations with integer values.
Minor
Efficiency
Reason
PLS_INTEGER
having a length of -2,147,483,648 to 2,147,483,647, on a 32bit system.
There are many reasons to use PLS_INTEGER
instead of NUMBER
:
PLS_INTEGER
uses less memoryPLS_INTEGER
uses machine arithmetic, which is up to three times faster than library arithmetic, which is used byNUMBER
.
Example (bad)
CREATE OR REPLACE PACKAGE BODY constants_up IS
co_big_increase CONSTANT NUMBER(5,0) := 1;
FUNCTION big_increase RETURN NUMBER IS
BEGIN
RETURN co_big_increase;
END big_increase;
END constants_up;
/
Example (good)
CREATE OR REPLACE PACKAGE BODY constants_up IS
co_big_increase CONSTANT PLS_INTEGER := 1;
FUNCTION big_increase RETURN PLS_INTEGER IS
BEGIN
RETURN co_big_increase;
END big_increase;
END constants_up;
/