DISABLE ADBLOCK

ADBlock is blocking some content on the site

ADBlock errore
 Checked

Question

Why do i come across compilation errors for the code below?? Have i gone wrong in the nesting ? I get the error as encountered DECLARE when expecting BEGIN..

DECLARE
BEGIN
   DECLARE 
      FUNCTION fn_Add1 (p_n1 NUMBER, p_n2 NUMBER) 
      RETURN NUMBER 
      AS 
      BEGIN 
        RETURN fn_Add2(p_n1,p_n2,40);
      END;

   DECLARE
     FUNCTION fn_Add2 (p_n1 NUMBER, p_n2 NUMBER,p_n3 NUMBER) 
     RETURN NUMBER 
     AS 
     BEGIN 
       RETURN (p_n1+p_n2+p_n3); 
     END; 
END;
BEGIN 
   DBMS_OUTPUT.PUT_LINE (fn_Add1(20,30)); 
END;
/

Solution

Remove the nested BEGIN and DECLARE - this way it should work:

DECLARE
  FUNCTION fn_Add2 (p_n1 NUMBER, p_n2 NUMBER,p_n3 NUMBER) 
  RETURN NUMBER IS 
  BEGIN 
      RETURN (p_n1+p_n2+p_n3); 
  END; 

  FUNCTION fn_Add1 (p_n1 NUMBER, p_n2 NUMBER) 
  RETURN NUMBER IS 
  BEGIN 
     RETURN fn_Add2(p_n1,p_n2,40);
  END;

BEGIN 
  DBMS_OUTPUT.PUT_LINE (fn_Add1(20,30)); 
END;
/

p.s.: I think it should be IS and not AS as well. Good luck!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow