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