Home > Database > Mysql Tutorial > Oracle中将字符串转换成数组

Oracle中将字符串转换成数组

WBOY
Release: 2016-06-07 17:21:31
Original
1715 people have browsed it

Oracle中将字符串转换成数组,并根据需要返回指定位置的数组成员

Oracle中将字符串转换成数组,并根据需要返回指定位置的数组成员

create or replace function GetElementFromArrayByIndex(Liststr in varchar2,sPlitVal in varchar2,iPos integer) return varchar2 is
/*
Liststr--传入将要被分割的字符串
sPlitVal--用来分割的字符串
iPos--获取分割后的数组中该位置的元素值

*/
  type tt_type is table of varchar2(100) INDEX BY BINARY_INTEGER;
  V1 tt_type;
  --FieldNames转化为数组
  TmpStr varchar2(100);
  Str    varchar2(4000);
  j      integer;
begin
  Str := Liststr;
  j  := 0;
  IF Instr(Liststr, sPlitVal, 1, 1) = 0 THEN
    V1(j) := Liststr;
    j := j + 1;
  else
    While Instr(str, sPlitVal, 1, 1) > 0 Loop
      TmpStr := Substr(str, 1, Instr(str, sPlitVal, 1, 1) - 1);
   
      V1(j) := TmpStr;
      str := SubStr(Str, Instr(str, sPlitVal, 1, 1) + length(sPlitVal), length(str));
      j := j + 1;
    end loop;
    if not str is null then
      --将最后一个保存
      V1(j) := str;
      j := j + 1;
    end if;
  end if;
  if iPos>j-1 or iPos    --超出数组长度
    return '';
  end if;
  return V1(ipos);
end;

linux

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template