oracle | 判断str1是否包含str2

/**
 * 判断str1是否包含str2.
 * @param str1 数组型字符串,以逗号分割
 * @param str2
 * @return 如果str1包含str2,则返回1,否则返回-1
 * @Author: xDer
 */
create or replace function exinstr(str1 in varchar2, str2 in varchar2)
return integer as
  Result integer;
  v_column_value varchar2(4000);
  cursor cur is
  select column_value from table(fn_split(str1,','));
  c_row cur%rowtype;

begin
  open cur;
  loop
    fetch cur into c_row;
    exit when cur%notfound;
    v_column_value := c_row.column_value;
    if v_column_value = str2 then
     Result := 1;
     return(Result);
     exit;
    else
     continue;
    end if;
  end loop;
  close cur;
  
  Result :=-1;
  
  return(Result);
  
   exception when others then 
    begin
        Result := -1;
        return(Result);
    end;
  
end exinstr;

  

原文地址:https://www.cnblogs.com/xder/p/5152370.html