Using NUMBER, PLS_INTEGER and SIMPLE_INTEGER in PL/SQL code Options

codeling Posts: 1100 Points: 4620
Posted: Wednesday, June 12, 2019 8:58:18 AM

Avoid declaring NUMBER variables or subtypes with no precision.

If you do not specify precision NUMBER is defaulted to 38 or the maximum supported by your system, whichever is less. You may well need all this precision, but if you know you do not, you should specify whatever matches your needs.


codeling Posts: 1100 Points: 4620
Posted: Wednesday, June 12, 2019 8:59:37 AM

Try to use PLS_INTEGER instead of NUMBER for arithmetic operations with integer values (no decimal point).

PLS_INTEGER has a length of -2,147,484,648 to 2,147,484,648 , on a 32 bit 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.

codeling Posts: 1100 Points: 4620
Posted: Wednesday, June 12, 2019 9:01:31 AM

With Oracle 11g and above, the new data type SIMPLE_INTEGER has been introduced. It is a sub-type of PLS_INTEGER and covers the same range. The basic difference is that

  • SIMPLE_INTEGER is always NOT NULL when the value of the declared variable is never going to be NULL then you can declare it as SIMPLE_INTEGER.
  • Another major difference is that you will never face a numeric overflow using SIMPLE_INTEGER as this data type wraps around without giving any error.
  • Also SIMPLE_INTEGER data type gives major performance boost over PLS_INTEGER when code is compiled in ‘NATIVE’ mode, because arithmetic operations on SIMPLE_INTEGER type are performed directly at the hardware level.
Users browsing this topic
Guest