Search This Blog

Wednesday, November 13, 2013

Dancing with Oracle Package with Code only

CREATE OR REPLACE PACKAGE PL_PKG AS 

--Public Variables Declaration
v_tax NUMBER;

--Public Procedures Declaration
PROCEDURE CALCULATOR;

--Public Functions Declaration
FUNCTION TAX (P_VALUE IN NUMBER) RETURN NUMBER;

END PLPU04;
CREATE OR REPLACE 
PACKAGE BODY PL_PKG AS

--Private Variables Declaration
V_COUNTER NUMBER DEFAULT 0;


--Forward Declaration
PROCEDURE P_SP_CALC(NUM IN NUMBER);


--Body Implementation
PROCEDURE CALCULATOR
AS
BEGIN
--Reference Resolved
P_SP_CALC(100);
V_COUNTER := V_COUNTER+1;
DBMS_OUTPUT.PUT_LINE ('V_COUNTER := '||V_COUNTER);
END CALCULATOR;


--The Implementation
PROCEDURE P_SP_CALC(NUM IN NUMBER)
AS
BEGIN
NULL;
END P_SP_CALC;

FUNCTION TAX (P_VALUE IN NUMBER) RETURN NUMBER IS
    V_RATE NUMBER := 0.1;
BEGIN
    RETURN (P_VALUE * V_RATE);
END TAX;


--Initialization Portion(Should be at the end of the package body)
BEGIN
V_COUNTER := 100;

END PLPU04;
DECLARE
  P_VALUE NUMBER;
  v_Return NUMBER;
BEGIN
  PL_PKG .CALCULATOR();
  PL_PKG .CALCULATOR();
  PL_PKG .CALCULATOR();
  P_VALUE := NULL;

  v_Return := PLPU04.TAX(P_VALUE => P_VALUE);
  DBMS_OUTPUT.PUT_LINE('v_Return = ' || v_Return);
END;

No comments: