Skip to main content
← PL/SQL Topics

Language Basics

Explain PLS_INTEGER, BINARY_INTEGER and SIMPLE_INTEGER

PLS_INTEGER, BINARY_INTEGER and SIMPLE_INTEGER

ExplanationOracle Fusion / EBS · Technical · PL/SQLHigh confidenceGenerated

These are hardware integer types that compute faster than NUMBER; SIMPLE_INTEGER never overflows or goes NULL.

How it works

NUMBER uses a portable decimal representation — accurate but slow for counters and loop indexes. PLS_INTEGER (and its older synonym BINARY_INTEGER) is a signed 32-bit machine integer: arithmetic is much faster, but it raises ORA-01426 on overflow. SIMPLE_INTEGER is a PLS_INTEGER subtype declared NOT NULL that wraps around silently instead of overflowing and is the fastest option, especially with native compilation. Use PLS_INTEGER for loop counters and array indexes.

How it works
DECLARE
  v_counter   PLS_INTEGER := 0;
  v_fast      SIMPLE_INTEGER := 0;   -- must be initialized, never NULL
BEGIN
  FOR i IN 1 .. 1000000 LOOP
    v_counter := v_counter + 1;
    v_fast    := v_fast + 1;
  END LOOP;
  DBMS_OUTPUT.PUT_LINE(v_counter || ' / ' || v_fast);
END;
/

Related questions

GroundingGenerated

Model-generated, grounded against the curated knowledge layer. Check specifics against your instance.

Have a follow-up, or a different question?

Continue in Ask Oracle AI