oracle 分割字符串
declare str varchar2(1000):='aas,,ss';
sign varchar2(10):=',';
currentIndex number;
startIndex number;
endIndex number;
type str_type is table of varchar2(30) index by binary_integer;
arr str_type;
begin
currentIndex := 0;
startIndex := 0;
loop
currentIndex := currentIndex + 1;
endIndex := instr(str, sign, 1, currentIndex);
if (endIndex <= 0) then
exit;
end if;
arr(currentIndex) := trim(substr(str,
startIndex + 1,
endIndex - startIndex - 1));
startIndex := endIndex;
end loop;
--取最后一个字符串:
arr(currentIndex) := substr(str, startIndex + 1, length(str));
for i in 1..currentIndex loop
dbms_output.put_line(arr(i));
end loop;
end;
浙公网安备 33010602011771号