← PL/SQL Topics

Packages & Modularity

Explain procedure/function overloading in PL/SQL packages

Overloading

Oracle Fusion / EBS · Technical · PL/SQL

GeneralHigh confidence

Multiple subprograms in one package can share a name if their parameter lists differ enough.

Grounded in: Curated Oracle knowledge layer — PL/SQL

How it works

Within one package, two or more subprograms can share the same name as long as their parameter lists differ enough for PL/SQL to pick the right one at compile time — a different number of parameters, or parameters of different (non-family) datatypes. Parameter names and default values alone aren't enough to distinguish two overloads from each other.

How it works
CREATE OR REPLACE PACKAGE fmt_pkg AS
  FUNCTION format_value(p_value NUMBER) RETURN VARCHAR2;
  FUNCTION format_value(p_value DATE) RETURN VARCHAR2;
END fmt_pkg;
/

CREATE OR REPLACE PACKAGE BODY fmt_pkg AS
  FUNCTION format_value(p_value NUMBER) RETURN VARCHAR2 IS
  BEGIN
    RETURN TO_CHAR(p_value, '999,999.00');
  END;

  FUNCTION format_value(p_value DATE) RETURN VARCHAR2 IS
  BEGIN
    RETURN TO_CHAR(p_value, 'DD-MON-YYYY');
  END;
END fmt_pkg;
/

Related Questions

Have a follow-up, or a different question?

Continue in Ask Oracle AI