从 PLSQL 块中的存储函数获取选定值

Get the selected value from a stored function in a PLSQL block

我有一个存储的 pl/sql 块,我需要 运行,该块调用存储的函数并获取返回值。

函数(使用 SELECT)从 table 中选择一个值,如果函数 运行 成功,returns 数值为 0 或 1。从 0 到 100 的 table 运行ges 中选择的值。 因此,当我 运行 SQLDeveloper 中的块时,我得到 1 或 0,但是当我 运行 块外部的函数时,我得到 运行ge 中的值。

当我运行

fetch_db_hit_ratio(1)

我在 运行ge 中得到一个值。但是当我运行块

"DECLARE  
 RetVal NUMBER; 
BEGIN  
 RetVal := fetch_db_hit_ratio(1); 
END;  
"

我得到 0 或 1,我知道我实际上读取了 retVal,但我如何读取函数选择的值?

这里是一个简化的功能代码

create or replace function    fetch_db_hit_ratio (dummy in number) return  number is
SUCCESS constant int :=0;
FAILURE constant int :=1;
errcode number:=NULL;
errmsg varchar2(1000) :=NULL;
step varchar2(1000) := 'some_text';
begin

begin
    select values(a) from some_table where condition;
exception
    when NO_DATA_FOUND then NULL;
end;

exception
when others then
    errcode:=sqlcode;
    errmsg:=substr(sqlerrm,1,100);
    --rp_message(errcode,errmsg,step,3);
    return -1;
end;

在你的情况下,我看到 2 个选项 - 任一函数 returns 记录有 2 个值:

CREATE OR REPLACE TYPE ret_val_type AS RECORD(
  func_result NUMBER,
  sql_result NUMBER
);

CREATE OR REPLACE FUNCTION fetch_db_hit_ratio (dummy IN NUMBER)
return rev_val_type

或创建带有 out 参数的函数:

create or replace function fetch_db_hit_ratio (dummy in number, sql_result out number)
return number