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 memory
  • PLS_INTEGER uses machine arithmetic, which is up to three times faster than library arithmetic, which is used by NUMBER.

Example (bad)

1
2
3
4
5
6
7
8
9
create or replace package body constants is
   k_big_increase constant number(1,0) := 1;

   function big_increase return number is
   begin
      return k_big_increase;
   end big_increase;
end constants;
/

Example (good)

1
2
3
4
5
6
7
8
9
create or replace package body constants is
   k_big_increase constant pls_integer := 1;

   function big_increase return pls_integer is
   begin
      return k_big_increase;
   end big_increase;
end constants;
/