oracle 执行包时出错
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20280148/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Getting error while Executing Package
提问by ram12393
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.
回答by Mureinik
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;
回答by halfbit
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;
/
回答by Avrajit Roy
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.
您需要执行包,即您执行包中的存储过程、函数等。