Skip to content

Instantly share code, notes, and snippets.

@DamianReeves
Created March 24, 2015 12:11
Show Gist options
  • Save DamianReeves/b861aeeae2efadeb6d03 to your computer and use it in GitHub Desktop.
Save DamianReeves/b861aeeae2efadeb6d03 to your computer and use it in GitHub Desktop.
Oracle CsvToTable Function
create or replace function csvToTable(p_clob_text in varchar2)
return sys.dbms_debug_vc2coll pipelined
is
next_new_line_indx pls_integer;
remaining_text varchar2(20000);
next_piece_for_piping varchar2(20000);
begin
remaining_text := p_clob_text;
loop
next_new_line_indx := instr(remaining_text, ',');
next_piece_for_piping :=
case
when next_new_line_indx <> 0 then
trim(substr(remaining_text, 1, next_new_line_indx-1))
else
trim(substr(remaining_text, 1))
end;
remaining_text := substr(remaining_text, next_new_line_indx+1 );
pipe row(next_piece_for_piping);
exit when next_new_line_indx = 0 or remaining_text is null;
end loop;
return;
end csvToTable;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment