Can we have a Procedure in Specification but not in Package body. If yes then whats the use of it?

Questions by Sant_parkash   answers by Sant_parkash

Showing Answers 1 - 19 of 19 Answers

nidhi

  • Nov 26th, 2007
 

Yes, we can have procedure in the specification but not in the package body. The use of this is that we can write any code in that procedure later on.

  Was this answer useful?  Yes

raghu iyer

  • Jul 11th, 2011
 

Hi,
Its Not possible..... all the sub programs declared in spec must be implemented in the body. In this case these sub programs will be private for this package only.

Raghu Iyer

  Was this answer useful?  Yes

Sudhanshu

  • Jul 26th, 2016
 

Code
  1. CREATE OR REPLACE PACKAGE Test_pkg AS

  2.   2    PROCEDURE Proc1;

  3.   3  END;

  4.   4  /

  5.  

  6. PACKAGE created

  7.  

  8. CREATE OR REPLACE PACKAGE BODY Test_pkg AS

  9.   2  

  10.   3    PROCEDURE proc1 IS

  11.   4    BEGIN

  12.   5      proc2;

  13.   6    END;

  14.   7  

  15.   8    PROCEDURE Proc2 IS

  16.   9    BEGIN

  17.  10      dbms_output.put_line(proc2 IS being executed);

  18.  11    END;

  19.  12  

  20.  13  END;

  21.  14  /

  22.  

  23. Warning: PACKAGE BODY created WITH compilation errors

  24. Error: PLS-00313: PROC2 NOT declared IN this scope

  25.  

  26. This IS happening because we are calling Proc2 which declared later IN the PACKAGE. IN this CASE our choices are:

  27.  

  28. DECLARE pro2 before the PROCEDURE which calls it

  29.  

  30.  CREATE OR REPLACE PACKAGE BODY Test_pkg AS

  31.   2  

  32.   3  

  33.   4    PROCEDURE Proc2 IS

  34.   5    BEGIN

  35.   6      dbms_output.put_line(proc2 IS being executed);

  36.   7    END;

  37.   8  

  38.   9    PROCEDURE proc1 IS

  39.  10    BEGIN

  40.  11      proc2;

  41.  12    END;

  42.  13  

  43.  14  END;

  44.  15  /

  45.  

  46. PACKAGE BODY created

  47. USE forward declaration.

  48.  

  49. CREATE OR REPLACE PACKAGE BODY Test_pkg AS

  50.   2  

  51.   3    PROCEDURE Proc2;

  52.   4  

  53.   5    PROCEDURE proc1 IS

  54.   6    BEGIN

  55.   7      proc2;

  56.   8    END;

  57.   9  

  58.  10    PROCEDURE Proc2 IS

  59.  11    BEGIN

  60.  12      dbms_output.put_line(proc2 IS being executed);

  61.  13    END;

  62.  14  

  63.  15  

  64.  16  END;

  65.  17  /

  66.  

  67. PACKAGE BODY created

  68.  

  69. SQL> EXEC test_pkg.Proc1;

  70.  

  71. proc2 IS being executed

  72.  

  73. PL/SQL PROCEDURE successfully completed

  Was this answer useful?  Yes

aak

  • Sep 15th, 2016
 

No, You can add the proc in body and not declare it in the spec.. this is ok as it would mean that that proc is a private procedure but visa versa is not possible. It would give compilation error.

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions