首页 > 代码库 > Oracle 截取字符串

Oracle 截取字符串

如下有一个创建函数的代码,是将一穿字符串按照逗号‘,’分割成若干段

create or replace function SplitStringByComma(aName in varchar2) return myArrayType is
Result myArrayType;
len number;
i integer;
j integer;
p integer;
Comma varchar2(1);
s number(10);
tempaName varchar2(4000);
c myArrayType(是一个Type) := myArrayType();
begin

tempaName:=aName;
if(aName is null) then
tempaName:=‘-98645353‘;
end if;


len:= Length(tempaName);
p:= 1;
i :=1;
j :=0;
loop
EXIT WHEN i>len;
Comma := substr(tempaName,i,1);
if (Comma=‘,‘) then
c.extend;
s := substr(tempaName,p,i-p);
c(c.count) := s;
j := j+1;
p := i+1;
end if;

i:=i+1;
end loop;

c.extend;
s := substr(tempaName,p,i-p);
c(c.count) := s;
Result := c;
return(Result);
end SplitStringByComma;

Oracle 截取字符串