如何在包中调用 Oracle 过程?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12143798/
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
How to call an Oracle procedure within a package?
提问by Marcie
I'm trying to call an Oracle stored procedure within a package and I'm getting this error: SQL Error: ORA-06576: not a valid function or procedure name
我正在尝试调用包中的 Oracle 存储过程,但出现此错误:SQL 错误:ORA-06576:不是有效的函数或过程名称
I'm using SQL Developer and this is the command I'm using
我正在使用 SQL Developer,这是我正在使用的命令
call WEATHERDATAUPDATES.GetLastRunDate("WeatherData")
Here is the package/procedure
这是包/程序
PACKAGE BODY WEATHERDATAUPDATES AS
PROCEDURE GetLastRunDate(PROCESS IN VARCHAR2, RUNDATE OUT DATE) AS
BEGIN
SELECT rundate FROM Marcie.last_rundate
where process = PROCESS;
END GetLastRunDate;
END WEATHERDATAUPDATES;
I'm pretty new to Oracle Packages and not sure what I'm missing. I tried searching, but can't find an answer that works. Can someone tell me what I'm missing?
我对 Oracle Packages 很陌生,不确定我错过了什么。我尝试搜索,但找不到有效的答案。有人可以告诉我我错过了什么吗?
Thanks, Marcie
谢谢,玛西
回答by cagcowboy
GetLastRunDate has 2 parameters, (process and rundate), but you're only passing 1 in your call.
GetLastRunDate 有 2 个参数(进程和运行日期),但您只在调用中传递 1 个参数。
Since you want to pass the second parameter out, one option would be to make it function and return the rundate.
由于您想将第二个参数传递出去,一种选择是使其起作用并返回运行日期。
PACKAGE BODY WEATHERDATAUPDATES AS
FUNCTION GetLastRunDate(PROCESS IN VARCHAR2)
RETURN DATE
AS
lDate DATE;
BEGIN
SELECT rundate
INTO lDate
FROM Marcie.last_rundate
where process = PROCESS;
RETURN lDate;
END GetLastRunDate;
END WEATHERDATAUPDATES;
回答by davidmontoyago
In your procedure you are not putting the retrieved value anywhere, you should use INTO
:
在您的程序中,您没有将检索到的值放在任何地方,您应该使用INTO
:
...
PROCEDURE GetLastRunDate(PROCESS IN VARCHAR2, RUNDATE OUT DATE) AS
BEGIN
SELECT rundate
INTO RUNDATE
FROM Marcie.last_rundate
where process = PROCESS;
END GetLastRunDate;
...
In the call pass the variable for the out parameter RUNDATE OUT DATE
.
在调用中为 out 参数传递变量RUNDATE OUT DATE
。
Put the call in a PL/SQL block:
将调用放在 PL/SQL 块中:
DECLARE
lastRunDate DATE;
BEGIN
WEATHERDATAUPDATES.GetLastRunDate("WeatherData",lastRunDate);
-- do something with lastRunDate
END;
回答by Jeffrey Kemp
You have shown the BODY of your package, but not the specification - check that GetLastRunDate
is declared in the package spec.
您已显示包的 BODY,但未显示规范 - 检查GetLastRunDate
包规范中声明的内容。