Skip to content

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_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)

1
2
3
4
5
6
7
8
9
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;
/