Created
March 24, 2015 12:11
-
-
Save DamianReeves/b861aeeae2efadeb6d03 to your computer and use it in GitHub Desktop.
Oracle CsvToTable Function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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