我有一个简单的测试函数,我传入一个特定的ID(我从中选择的表的主键),并在其上计算一个简单的函数和参数。
框架代码和测试:
create or replace function test(id varchar2, area float) return float is theRow forest%ROWTYPE; begin select * into theRow from forest where Forest_No = id; return area / theRow.Area; end; begin select test('1', 16000) from dual; end;
输出:
[2019-10-14 21:19:10] [65000][6550] ORA-06550: line 2, column 5: [2019-10-14 21:19:10] PLS-00428: an INTO clause is expected in this SELECT statement
据我所知,文档和示例使用相同的顺序和语法,对此我一无所知。我尝试过将in子句移到Postgresql的末尾,但这没有用。
我在这里错过了什么?
问题在于通话声明中。
每当select
在plsql块中使用语句时,它都必须具有into
子句才能将返回值分配给变量。
您应该从调用代码中删除begin
和end
:
--begin -- remove this select test('1', 16000) from dual; --end; -- remove this
或者,如果要在plsql块中使用它,请添加into子句:
Declare Area_ float(precision); begin select test('1', 16000) into area_ from dual; -- use area_ in your code wherever required dbms_output.put_line('area: ' || area_); end;
干杯!!