If you want to make the parameter optional, you must specify a default value. I would be surprised if the default works correctly if it is not specified in the body declaration.
I'm used to making all package specification declarations exact copies of package body declarations to avoid problems.
EDIT:
As the OP points out, it can only be in the specification, and it works. If it is in the body, but not in the specification, an error occurs:
SQL> CREATE OR REPLACE PACKAGE p AS 2 PROCEDURE prc(p1 VARCHAR2, p2 VARCHAR2); 3 END; 4 / Package created SQL> CREATE OR REPLACE PACKAGE BODY p AS 2 PROCEDURE prc(p1 VARCHAR2 DEFAULT 'P1', p2 VARCHAR2) 3 IS 4 BEGIN 5 dbms_output.put_line(p1||','||p2); 6 END; 7 END; 8 / Warning: Package body created with compilation errors SQL>
But if only in the specification, everything works:
SQL> CREATE OR REPLACE PACKAGE p AS 2 PROCEDURE prc(p1 VARCHAR2 DEFAULT 'P1Dflt', p2 VARCHAR2); 3 END; 4 / Package created SQL> CREATE OR REPLACE PACKAGE BODY p AS 2 PROCEDURE prc(p1 VARCHAR2, p2 VARCHAR2) 3 IS 4 BEGIN 5 dbms_output.put_line(p1||','||p2); 6 END; 7 END; 8 / Package body created SQL> DECLARE 2 BEGIN 3 p.prc(p2=>'Test'); 4 END; 5 / P1Dflt,Test PL/SQL procedure successfully completed SQL>
However, the answer to the question of what is the difference, it seems that there is no difference between putting the default value in the specification or in both places - the end result is the same. I would like to confirm my conviction that you should put it in both places for documentary purposes.
source share