oracle10g字符串逗号分割,并按照顺序写到新的列中
实现效果:
create or replace function Get_ZGDWJC ( av_str varchar2, --要分割的字符串 av_split varchar2 --分隔符号 ) return varchar2 is lv_str varchar2(1024); lv_strOfIndex varchar2(1024); all_zgdw varchar2(2024); new_zgdw varchar2(2024); lv_length number; i number; j NUMBER := 0; k number; begin lv_str:=ltrim(rtrim(av_str)); lv_str:=concat(lv_str,av_split); lv_length:=Get_StrArrayLength(av_str,av_split);--获取输入字符串的长度 i :=lv_length; LOOP if j=0 then lv_strOfIndex:=substr(lv_str,1,instr(lv_str,av_split)-length(av_split)); all_zgdw := GET_DWJC(lv_strOfIndex);--根据单位编码获得单位简称 else k :=lv_length-j; lv_strOfIndex:=substr(lv_str,instr(lv_str,av_split,1,k)+length(av_split),instr(lv_str,av_split,1,k+1)-instr(lv_str,av_split,1,k)-length(av_split)); new_zgdw:=GET_DWJC(lv_strOfIndex); all_zgdw :=all_zgdw||','||new_zgdw; end if; j :=i-1; i:=i-1; exit when j=0; end loop; return all_zgdw; end Get_ZGDWJC;
获取字符串长度函数:
create or replace function Get_StrArrayLength ( av_str varchar2, --要分割的字符串 av_split varchar2 --分隔符号 ) return number is lv_str varchar2(1000); lv_length number; begin lv_str:=ltrim(rtrim(av_str)); lv_length:=0; while instr(lv_str,av_split)<>0 loop lv_length:=lv_length+1; lv_str:=substr(lv_str,instr(lv_str,av_split)+length(av_split),length(lv_str)); end loop; lv_length:=lv_length+1; return lv_length; end Get_StrArrayLength;
获取单位简称函数:
create or replace function GET_DWJC (p_WTFWZGDW ks_xqpm_dwbm.Dwbmdm%type) return t_wtfw.dwbmid%type is temp varchar2(500); c integer; Result t_wtfw.dwbmid%type; begin c:=0; select count(DWJC) into c from ks_xqpm_dwbm where DWBMDM = p_WTFWZGDW ; if c>0 then select DWJC into Result from ks_xqpm_dwbm where DWBMDM = p_WTFWZGDW ; /* Result:=temp;*/ else Result:=null; end if; return(Result); end GET_DWJC;