I’m pretty sure that everybody at least once in his professional coding life had the need to convert a string of character separated values into tokens or rows.
Let’s be honest, we all ended writing something like
1 2 3 4 5 6 7 8 9 10 |
for k in 1..length(mystring) loop if substr(mystring), k, 1) = ',' then ...bla... ...bla... else strBuffer := strBuffer || substr(mystring, k, 1); ...bla... ...bla... end if; end loop; |
Problem is that among all those “bla” it’s quite easy to forget something (is there always a separator at the very end of the string? Any space between values and separators? Did I clean the buffer?) and in such code bugs might find a comfortable home.
Why should we write such risky code to do something that can be achieved differently in a completely reliable, fast and elegant way? And all of this just using one powerful feature that Oracle kindly introduced with version 10g (drum roll): regular expressions!