Skip to main content
← PL/SQL Topics

Language Basics

Explain user-defined SUBTYPEs in PL/SQL

User-Defined SUBTYPEs

ExplanationOracle Fusion / EBS · Technical · PL/SQLHigh confidenceGenerated

SUBTYPE gives an existing type a meaningful name, optionally with a size/range constraint.

How it works

SUBTYPE declares an alias for an existing type so intent is documented in one place and reused. An unconstrained subtype (SUBTYPE id_t IS PLS_INTEGER) is fully interchangeable with its base type. A constrained subtype (SUBTYPE small_str IS VARCHAR2(30)) enforces the limit. Defining subtypes in a package spec lets the whole schema share one definition of, say, an 'amount' or an 'employee id'.

How it works
CREATE OR REPLACE PACKAGE types_pkg AS
  SUBTYPE amount_t   IS NUMBER(18,2);
  SUBTYPE entity_id_t IS PLS_INTEGER;
  SUBTYPE short_name_t IS VARCHAR2(60);
END types_pkg;
/
DECLARE
  v_price types_pkg.amount_t := 19.99;
  v_id    types_pkg.entity_id_t := 100;
BEGIN
  DBMS_OUTPUT.PUT_LINE(v_id || ': ' || v_price);
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