ITPub博客

首页 > Linux操作系统 > Linux操作系统 > 函数-求字符串中字串的个数

函数-求字符串中字串的个数

原创 Linux操作系统 作者:sieper 时间:2010-05-25 15:05:17 0 删除 编辑

create or replace function numofstr(par in clob, str in varchar2)
--这个函数输出str在par中重复多少次
 return number is
  f_num        number := 0;
  f_clob       clob;
  f_instr      number := -1;
  f_strlength  number := 0;
  f_cloblength number := 0;
begin
  f_instr := dbms_lob.instr(par, str);
  if (f_instr < 0) then
    return f_num;
  end if;
  f_strlength  := dbms_lob.getlength(str);
  f_clob       := par;
  f_cloblength := dbms_lob.getlength(f_clob);
  while f_instr > 0 loop
    f_num        := f_num + 1;
    f_clob       := dbms_lob.substr(f_clob,
                                    f_cloblength - f_instr + f_strlength,
                                    f_instr + f_strlength);
    f_instr      := dbms_lob.instr(f_clob, str);
    f_cloblength := dbms_lob.getlength(f_clob);
  end loop;
  return f_num;
exception
  when others then
    dbms_output.put_line(' error occurs!');
end;

 

写在f-long


 

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/11813230/viewspace-663625/ ,如需转载,请注明出处,否则将追究法律责任。

上一篇: oracle ddl
下一篇: ora-00604 ORA-01422
请登录后发表评论 登录
全部评论

注册时间:2009-03-17

  • 博文量
    87
  • 访问量
    210537