从存储过程返回结果

时间:2013-06-25 06:33:04

标签: sql oracle stored-procedures plsql

我有一个执行select语句的存储过程。我创建了另一个存储过程,它调用了早期的存储过程,但是能够获得结果。以下是脚本

过程Proc1:

create or replace
PROCEDURE p_procedure3(custid IN number, custname OUT varchar2) IS
BEGIN

SELECT firstname 
INTO custname
FROM customer_s
WHERE customerid = custid;

END p_procedure3;

PROC2:

create or replace
procedure finalexecution
DECLARE
l_name varchar2(20);
BEGIN

p_procedure3(644, l_name);

dbms_output.put_line(l_name);

END;

但是什么时候执行exex finalexecution;

低于错误

Error starting at line 8 in command:
exec finalexecution
Error report:
ORA-06550: line 1, column 7:
PLS-00905: object CIMNEWUSER.FINALEXECUTION is invalid
ORA-06550: line 1, column 7:
PL/SQL: Statement ignored
06550. 00000 -  "line %s, column %s:\n%s"
*Cause:    Usually a PL/SQL compilation error.
*Action:

2 个答案:

答案 0 :(得分:2)

您的finalexecution程序包含错误。您应该使用ISAS代替DECLARE。查看documentaion了解详情。

如果有任何错误,您可以查看all_errors视图以找出导致错误的原因。

答案 1 :(得分:1)

将第二个程序更改为:

create or replace
procedure finalexecution as
  l_name varchar2(20):='';
BEGIN
  p_procedure3(644, l_name);
  dbms_output.put_line(l_name);
END;

有关详细信息,请参阅Call a stored procedure with another in Oracle