Oracle PL/SQL - PLS_INTEGER and BINARY_INTEGER Data Types

Introduction

The PL/SQL data types PLS_INTEGER and BINARY_INTEGER are identical.

The PLS_INTEGER data type stores signed integers in the range -2,147,483,648 through 2,147,483,647, represented in 32 bits.

The PLS_INTEGER data type has these advantages over the NUMBER data type and NUMBER subtypes:

  • PLS_INTEGER values require less storage.
  • PLS_INTEGER operations use hardware arithmetic, so they are faster than NUMBER operations.

For efficiency, use PLS_INTEGER values for all calculations in its range.

A PLS_INTEGER value can be implicitly converted to a PLS_INTEGER subtype only if the value does not violate a constraint of the subtype.

Casting the PLS_INTEGER value NULL to the SIMPLE_INTEGER subtype raises an exception.

Demo

SQL>
SQL> --Violating Constraint of SIMPLE_INTEGER Subtype
SQL> DECLARE
  2   a SIMPLE_INTEGER := 1;
  3   b PLS_INTEGER := NULL;
  4  BEGIN--  ww w.j ava 2s .c  o m
  5   a := b;
  6  END;
  7  /
DECLARE
*
ERROR at line 1:
ORA-06502: PL/SQL: numeric or value error
ORA-06512: at line 5


SQL>

Related Topics