Split string into an array (Skip first character)
944438Jun 18 2012 — edited Jun 19 2012I have a string like:
,open,close,open
I want to parse the data into an array (without the first ','). I found and tweaked the following code, but the result was:
+<blank line> (think this is coming from the first ',')+
off
on
off
---------------------------------------
FUNCTION SPLIT (p_in_string VARCHAR2, p_delim VARCHAR2) RETURN t_array
IS
i number :=0;
pos number :=0;
lv_str varchar2(50) := p_in_string;
strings t_array;
BEGIN
-- determine first chuck of string
pos := instr(lv_str,p_delim,1,1);
-- while there are chunks left, loop
WHILE ( pos != 0) LOOP
-- increment counter
i := i + 1;
-- create array element for chuck of string
strings(i) := substr(lv_str,1,pos-1);
-- remove chunk from string
lv_str := substr(lv_str,pos+1,length(lv_str));
-- determine next chunk
pos := instr(lv_str,p_delim,1,1);
-- no last chunk, add to array
IF pos = 0 THEN
strings(i+1) := lv_str;
END IF;
END LOOP;
-- return array
RETURN strings;
END SPLIT;
I am working on a 9i database.