CREATEOR REPLACE FUNCTION split_key_value_pairs( input_string IN VARCHAR2, delimiter IN VARCHAR2 DEFAULT';', key_value_delimiter IN VARCHAR2 DEFAULT',' ) RETURN SYS_REFCURSOR AS output_cursor SYS_REFCURSOR; BEGIN OPEN output_cursor FOR SELECT SUBSTR(input_string, 1, INSTR(input_string, key_value_delimiter)-1) AS key, SUBSTR(input_string, INSTR(input_string, key_value_delimiter)+1) ASvalue FROM ( SELECTTRIM(REGEXP_SUBSTR(input_string, '[^'|| delimiter ||']+', 1, LEVEL)) AS input_string FROM DUAL CONNECTBY LEVEL <= REGEXP_COUNT(input_string, '[^'|| delimiter ||']+') ) WHERE input_string ISNOTNULL; RETURN output_cursor; END;