如何从存储过程调用存储函数并存储 return 值

How to call a stored function from a stored procedure and store the return value

当我在存储过程中执行此操作时:

   create procedure Proc1(
       startdate IN TIMESTAMP,
       ENDDATE IN TIMESTAMP
   )
   declare test_result number --line 55
    test_result:=Stored_function1(startdate,enddate,11,13); --line 56
END;

SQL 开发者抛出 2 个错误:

PLS-00103: Encountered the symbol "TEST_RESULT" when expecting one of the following: := . ( @ % ; not null range default character The symbol "." was substituted for "TEST_RESULT" to continue.

PLS-00103: Encountered the symbol "END" when expecting one of the following: begin function pragma procedure subtype type current cursor delete exists prior

Stored_function1是用户自定义的,带4个参数,不属于任何包。我哪里做错了,我该如何纠正?谢谢

在没有看到更多的情况下很难判断,但您的程序中似乎有一些语法错误。不需要DECLARE,55行末尾至少要有一个semi-colon,56行前至少要有一个BEGIN

这是一个基本框架:

Create or replace procedure my_procedure as
  test_result number;
BEGIN
  test_result := Stored_function1(startdate, enddate, 11, 13); 
END;