Oracle 中的函数。需要使用 Oracle Function 搜索并找到传递的参数

Functions in Oracle. Need to search and find the passed paramater using Oracle Function

我有一个要求,我需要使用 Oracle 参数化函数搜索并找到 table 列的值。

假设,如果我的 table 有一个名为 'Name' 的列,其中有 2 条记录,例如 'mike'、'steve'。

我需要创建一个函数,我将在其中传递名称作为输入参数,并且应该将此参数与 table 列 'Name' 的现有名称值进行比较或迭代。

如果传递的参数与列值匹配,那么函数应该return传递的参数

否则函数应该 return 声明 "passed name value doesn't exist".

例如,如果 table 中的名称列有 2 条记录,如 'mike'、'steve'。

现在,如果我将 'mike' 作为输入参数传递给函数,那么函数应该 return 'mike' 在其他情况下,如果我将 'john' 作为输入参数传递给函数,那么函数应该 return 表示 "passed name value doesn't exist".

请多多指教。

create or replace function does_name_exist(p_name in varchar2)
    return varchar2 is
    v_exists varchar2(1);
begin
    -- validate parameter
    select 'Y' into v_exists from my_table where name = p_name;

    -- if it exists
    return p_name;

    -- if it doesn't exist
    exception when NO_DATA_FOUND then
        return 'passed name value doesn''t exist';
end;
/