[英]Oracle - no function with name X exists in this scope
The function is clearly there, because I can navigate to it using SQL Developer and it compiles all fine, but when I try to use the function with or without "call", it throws: 该函数显然存在,因为我可以使用SQL Developer导航到它并且它编译得很好,但是当我尝试使用带或不带“call”的函数时,它抛出:
Error(36,24): PLS-00222: no function with name 'x' exists in this scope 错误(36,24):PLS-00222:此范围内不存在名称为“x”的函数
This is how the function looks like: 这是函数的样子:
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;
This is how I'm calling it: 这就是我所说的:
messaget := testfunction(somevalue);
where both messageT and somevalue are declared as varchar2 type. 其中messageT和somevalue都声明为varchar2类型。
Are cursors not allowed inside function or something like that? 游标内部不允许使用游标吗?
the error would be messaget := testcursor.column1;
错误将是messaget := testcursor.column1;
as the cursor is closed by then (you should just use testcursorrec.column2
. 当光标被关闭时(你应该使用testcursorrec.column2
。
you're code isn't checking for no rows, nor duplicate rows. 你的代码没有检查没有行,也没有重复行。 you can simplify this to 你可以简化这个
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;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.