Oracle PL/SQL/Stored Procedure Function/Overload

Материал из SQL эксперт
Версия от 10:01, 26 мая 2010; Admin (обсуждение | вклад) (1 версия)
(разн.) ← Предыдущая | Текущая версия (разн.) | Следующая → (разн.)
Перейти к: навигация, поиск

Overloaded local procedures.

 
SQL>
SQL> set serveroutput on
SQL>
SQL> DECLARE
  2    PROCEDURE LocalProc(p_Parameter1 IN NUMBER) IS
  3    BEGIN
  4      DBMS_OUTPUT.PUT_LINE("In version 1, p_Parameter1 = " ||
  5                           p_Parameter1);
  6    END LocalProc;
  7
  8    PROCEDURE LocalProc(p_Parameter1 IN VARCHAR2) IS
  9    BEGIN
 10      DBMS_OUTPUT.PUT_LINE("In version 2, p_Parameter1 = " ||
 11                           p_Parameter1);
 12    END LocalProc;
 13  BEGIN
 14    LocalProc(12345);
 15
 16    LocalProc("abcdef");
 17  END;
 18  /
In version 1, p_Parameter1 = 12345
In version 2, p_Parameter1 = abcdef
PL/SQL procedure successfully completed.
SQL>
SQL>



Use RESTRICT_REFERENCES with overloaded subprograms.

 
SQL>
SQL> CREATE OR REPLACE PACKAGE Overload AS
  2    FUNCTION TestFunc(p_Parameter1 IN NUMBER)
  3      RETURN VARCHAR2;
  4    PRAGMA RESTRICT_REFERENCES(TestFunc, WNDS, RNDS, WNPS, RNPS);
  5
  6    FUNCTION TestFunc(p_ParameterA IN VARCHAR2,
  7                      p_ParameterB IN DATE)
  8      RETURN VARCHAR2;
  9    PRAGMA RESTRICT_REFERENCES(TestFunc, WNDS, RNDS, WNPS, RNPS);
 10  END Overload;
 11  /
Package created.
SQL>
SQL> CREATE OR REPLACE PACKAGE BODY Overload AS
  2    FUNCTION TestFunc(p_Parameter1 IN NUMBER)
  3      RETURN VARCHAR2 IS
  4    BEGIN
  5      RETURN "Version 1";
  6    END TestFunc;
  7
  8    FUNCTION TestFunc(p_ParameterA IN VARCHAR2,
  9                      p_ParameterB IN DATE)
 10      RETURN VARCHAR2 IS
 11    BEGIN
 12      RETURN "Version 2";
 13    END TestFunc;
 14  END Overload;
 15  /
Package body created.
SQL>
SQL> SELECT Overload.TestFunc(1) FROM dual;
OVERLOAD.TESTFUNC(1)
--------------------------------------------------------------------------------
Version 1
SQL> SELECT Overload.TestFunc("abc", SYSDATE) FROM dual;
OVERLOAD.TESTFUNC("ABC",SYSDATE)
--------------------------------------------------------------------------------
Version 2
SQL>