For a basic comma delimited string. execute procedure below it is designed to wittle the record down a piece at a time. When p_input_string = p_output_value
it is done. Default is comma but you can pass in a different delimiter
parse_delimited_string(V_string, v_value, ';');
--- semicolon delimited
create or replace procedure parse_delimited_string(P_INPUT_STRING IN OUT VARCHAR2,
P_OUTPUT_VALUE OUT VARCHAR2,
P_DELIMITOR IN VARCHAR2 DEFAULT ',')
is
/*This Procedure will parse out the first field of a delimited string it will return
the result and a the orginal string minus the parsed out string.
the ideal would be to execute this procedure for each field you want to extract
from string. If you don't know how many values you need to parse out you can just
keep executing this until the p_input_strng equals the P_output_value
*/
begin
IF (instr(P_INPUT_STRING, P_DELIMITOR)) > 0
THEN
P_OUTPUT_VALUE := substr(P_INPUT_STRING, 1, (instr(P_INPUT_STRING, P_DELIMITOR)));
P_INPUT_STRING := regexp_replace(P_INPUT_STRING, P_OUTPUT_VALUE, '',1,1);
P_OUTPUT_VALUE := replace(P_OUTPUT_VALUE, P_DELIMITOR, '');
IF NVL(P_INPUT_STRING, ' ') = ' '
THEN
P_INPUT_STRING := P_OUTPUT_VALUE;
END IF;
ELSE
P_OUTPUT_VALUE := P_INPUT_STRING;
END IF;
end parse_delimited_string;