4

Table Structure:

Name       Null Type         
---------- ---- ------------ 
DPT_NO          NUMBER       
SALARY          NUMBER(10)   
PERIOD          VARCHAR2(10) 
START_DATE      DATE         
END_DATE        DATE     

Package:

CREATE OR REPLACE package body salary_sal AS
   PROCEDURE find_sal(c_dpt_no salary.dpt_no%TYPE) IS
   c_sal salary.salary%TYPE;
   BEGIN
      SELECT salary INTO c_sal
      FROM salary
      WHERE c_dpt_no= 108;
      dbms_output.put_line('Salary: '|| c_sal);
   END find_sal;
END salary_sal;

while executing above I'm getting following error

Error: PL/SQL: Compilation unit analysis terminated
Error(1,14): PLS-00201: identifier 'SALARY_SAL' must be declared
Error(1,14): PLS-00304: cannot compile body of 'SALARY_SAL' without its specification.

3 Answers 3

9

You're missing the declaration of the package. The idea is to separate the declaration of the package ("the header", if you will), so other packages/procedures/functions can compile against it from the body (the implementation).

In your case, you'd need something like:

CREATE OR REPLACE package salary_sal AS
   PROCEDURE find_sal(c_dpt_no salary.dpt_no%TYPE);
END salary_sal;

Now, once the package is declared, you can create its body:

CREATE OR REPLACE package body salary_sal AS
   PROCEDURE find_sal(c_dpt_no salary.dpt_no%TYPE) IS
   c_sal salary.salary%TYPE;
   BEGIN
      SELECT salary INTO c_sal
      FROM salary
      WHERE c_dpt_no= 108;
      dbms_output.put_line('Salary: '|| c_sal);
   END find_sal;
END salary_sal;
5
  • these two package will be execute separately?
    – ram12393
    Commented Nov 29, 2013 at 7:22
  • These are two different statements. This way you can create your package ("header") once and alter the body ("implementation") many times without have to break/re-compile other packages depending on it.
    – Mureinik
    Commented Nov 29, 2013 at 7:23
  • why we declare another package here?
    – ram12393
    Commented Nov 29, 2013 at 7:24
  • This is not another package - it the package and its body. See Oracle's docs for more details.
    – Mureinik
    Commented Nov 29, 2013 at 7:26
  • 1
    how to execute this package?
    – ram12393
    Commented Nov 29, 2013 at 7:27
0

The package needs a specification (i.e. a separate interface definition) as the error message says. You would have to add something like before the definition of the package body (i.e. its implementation):

CREATE OR REPLACE package salary_sal AS
   PROCEDURE find_sal(c_dpt_no salary.dpt_no%TYPE);
END salary_sal;
/
5
  • where to add your answer,i mean in package or body section ?
    – ram12393
    Commented Nov 29, 2013 at 7:16
  • It is not clear to me what you mean with "package section." Add that before your CREATE OR REPLACE package body salary_sal ... in your code. It is separate from the body but required by it.
    – halfbit
    Commented Nov 29, 2013 at 7:23
  • how to execute package?
    – ram12393
    Commented Nov 29, 2013 at 7:33
  • Packages do not get executed. They are containers for procedures, functions, types etc. It is kind of a code "module" in PL/SQL and has separate interface and implementation allowing other modules or code using the package while the implementation can vary (and have "private" procedures for example not mentioned in the package specification.) One example is the DBMS_OUTPUT package you are using. Its implementation may change between versions of Oracle but you do not need to care about that, you just rely on the specification (i.e. interface) of that module.
    – halfbit
    Commented Nov 29, 2013 at 7:56
  • well explanation.we can using these package by another implementation process like select and etc,.Isn't it?
    – ram12393
    Commented Nov 29, 2013 at 8:37
0

You neeed to create a package specifications and then only you can create a package body.

You need to execute the package i.e you execute the stored procedures,functions etc in the package.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.