微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Oracle – 此范围内不存在名称为X的函数

函数显然存在,因为我可以使用sql Developer导航到它并且它编译得很好,但是当我尝试使用带或不带“call”的函数时,它抛出:

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;

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐