簡體   English   中英

Oracle - 此范圍內不存在名稱為X的函數

[英]Oracle - no function with name X exists in this scope

該函數顯然存在,因為我可以使用SQL Developer導航到它並且它編譯得很好,但是當我嘗試使用帶或不帶“call”的函數時,它拋出:

錯誤(36,24):PLS-00222:此范圍內不存在名稱為“x”的函數

這是函數的樣子:

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;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM