WITH
  FUNCTION remove_duplicate_elements(p_in_str IN varchar2, p_delimiter IN varchar2 DEFAULT ',') RETURN varchar2 IS
  v_in_str varchar2(32767):= REPLACE(p_in_str,p_delimiter,',');
  v_res    varchar2(32767);
BEGIN
  --
  EXECUTE immediate 'select listagg(distinct cv,:p_delimiter) from (select (column_value).getstringval() cv from xmltable(:v_in_str))' 
     INTO v_res USING p_delimiter, v_in_str;
  --
  RETURN v_res;
  --
END;

--Test
SELECT remove_duplicate_elements('1, 2, 3, , , , 2, 3, 4, , , ') AS res FROM dual
UNION ALL 
SELECT remove_duplicate_elements('3 9 1 10 3 7 6 5 2 7 4 7 4 2 2 2 2 8 2 10 4 9 2 4 9 3 4 3 4 7',' ') AS res FROM dual
;