Turn on Compile-Time Warnings
ALTER SESSION SET PLSQL_WARNINGS = 'ENABLE:ALL'
Statement processed.
A Package with Overloading
CREATE OR replace PACKAGE salespkg AUTHID DEFINER
IS
PROCEDURE calc_total (zone_in IN VARCHAR2);
PROCEDURE calc_total (reg_in IN VARCHAR2);
END salespkg;
Package created.
CREATE OR replace PACKAGE BODY salespkg
IS
PROCEDURE calc_total (zone_in IN VARCHAR2)
IS
BEGIN DBMS_OUTPUT.PUT_LINE ('zone'); END;
PROCEDURE calc_total (reg_in IN VARCHAR2)
IS
BEGIN DBMS_OUTPUT.PUT_LINE ('region'); END;
END salespkg;
Package Body created.
Will This Work?
BEGIN
salespkg.calc_total ('zone15');
END;
ORA-06550: line 2, column 4: PLS-00307: too many declarations of 'CALC_TOTAL' match this callMore Details: https://docs.oracle.com/error-help/db/ora-06550
Get It To Work With Named Notation
BEGIN
salespkg.calc_total (zone_in => 'zone15');
END;
zone
Create New Version of Package
CREATE OR replace PACKAGE salespkg AUTHID DEFINER
IS
PROCEDURE calc_total (reg_in IN CHAR);
PROCEDURE calc_total (reg_in IN VARCHAR2);
END salespkg;
Package created.
The Package Body Compiles Too
CREATE OR replace PACKAGE BODY salespkg
IS
PROCEDURE calc_total (reg_in IN CHAR)
IS
BEGIN DBMS_OUTPUT.PUT_LINE ('region'); END;
PROCEDURE calc_total (reg_in IN VARCHAR2)
IS
BEGIN DBMS_OUTPUT.PUT_LINE ('region'); END;
END salespkg;
Package Body created.
Just Pass a String?
BEGIN
salespkg.calc_total ('reg11');
END;
ORA-06550: line 2, column 4: PLS-00307: too many declarations of 'CALC_TOTAL' match this callMore Details: https://docs.oracle.com/error-help/db/ora-06550
Use Named Notation?
BEGIN
salespkg.calc_total (reg_in => 'reg11');
END;
ORA-06550: line 2, column 4: PLS-00307: too many declarations of 'CALC_TOTAL' match this callMore Details: https://docs.oracle.com/error-help/db/ora-06550
Pass a Fixed Length String Explicitly?
DECLARE
l_char CHAR (2) := 'ab';
BEGIN
salespkg.calc_total (reg_in => l_char);
END;
ORA-06550: line 4, column 4: PLS-00307: too many declarations of 'CALC_TOTAL' match this callMore Details: https://docs.oracle.com/error-help/db/ora-06550
Ambiguous Overloading Due to Default Values
CREATE OR replace PACKAGE salespkg AUTHID DEFINER
IS
PROCEDURE calc_total (zone_in IN CHAR, date_in in DATE DEFAULT SYSDATE);
PROCEDURE calc_total (zone_in IN VARCHAR2);
END salespkg;
Package created.
CREATE OR replace PACKAGE BODY salespkg
IS
PROCEDURE calc_total (zone_in IN CHAR, date_in in DATE DEFAULT SYSDATE)
IS
BEGIN DBMS_OUTPUT.PUT_LINE ('zone with date'); END;
PROCEDURE calc_total (zone_in IN VARCHAR2)
IS
BEGIN DBMS_OUTPUT.PUT_LINE ('zone'); END;
END salespkg;
Package Body created.
Oh No! Still Ambiguous....
BEGIN
salespkg.calc_total ('reg11');
END;
ORA-06550: line 2, column 4: PLS-00307: too many declarations of 'CALC_TOTAL' match this callMore Details: https://docs.oracle.com/error-help/db/ora-06550
Ah, This One Works
BEGIN
salespkg.calc_total ('reg11', sysdate);
END;
zone with date