`
vencent888
  • 浏览: 139866 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
社区版块
存档分类
最新评论

字符串分割函数

阅读更多

--本文摘自klyuan

  1. Parameters:   
  2.    pi_string 要处理的字符   
  3.   pi_separator 分隔符   
  4.   pi_count 第n个分隔符   
  5. function get_part_char(pi_string in varchar2, pi_separator in varchar2, pi_count number) return varchar2 is  
  6.   pos number;   
  7.   c_pos number;   
  8. begin  
  9.   if pi_string is null or pi_separator is null then  
  10.      return '';   
  11.  end if;   
  12.     
  13.   if pi_count < 1 then  
  14.      return '';   
  15.   end if;   
  16.  if pi_count = 1 then  
  17.     pos := instr(pi_string, pi_separator);   
  18.     if pos = 0 then  
  19.         return pi_string;   
  20.     else  
  21.       return substr(pi_string,0,pos-1);   
  22.     end if;   
  23.   else  
  24.      pos := instr(pi_string, pi_separator,1,pi_count -1);   
  25.      c_pos := instr(pi_string, pi_separator, 1, pi_count)   
  26.      if pos = 0 then  
  27.         return '';   
  28.      end if;   
  29.      if c_pos = 0 then  
  30.          return substr(pi_string, pos+1, length(pi_string) - pos);   
  31.      else  
  32.         return substr(pi_string, pos+1, c_pos - pos -1);   
  33.      end if;   
  34.   end if;   
  35. end get_part_char;  
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics