该函数显然在那里,因为我可以使用 SQL Developer 导航到它并且编译一切正常,但是当我尝试使用带有或不带有“调用”的函数时,它会抛出:
Error(36,24): PLS-00222: no function with name 'x' exists in this scope
这是函数的样子:
create or replace function testfunction
(
somevalue in varchar2
)
return varchar2
AS
cursor testcursor IS
select column1, column2 from table1 t
where t.column1 = somevalue;
testcursorrec testcursor %rowtype;
messaget VARCHAR2(500);
begin
open testcursor ;
fetch testcursor into testcursorrec ;
close testcursor ;
messaget := testcursor.column1;
return messaget ;
end;
我是这样称呼它的:
messaget := testfunction(somevalue);
其中 messageT 和 somevalue 都声明为 varchar2 类型。
函数内部是否不允许使用游标或类似的东西?
最佳答案
错误将是 messaget := testcursor.column1;
因为此时光标已关闭(您应该只使用 testcursorrec.column2
。
你的代码没有检查没有行,也没有检查重复的行。您可以将其简化为
create or replace function testfunction
(
somevalue in table1.column1%type
)
return table1.column2%type
AS
messaget table1.column2%type; -- use %type where possible.
begin
select t.column2
into messaget
from table1 t
where t.column1 = somevalue
and rownum = 1;--only if you dont care if theres 2+ rows.
return messaget;
exception
when no_data_found
then
return null; -- if you want to ignore no rows.
end;
关于Oracle - 此范围内不存在名称为 X 的函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13583574/