Skip to Main Content

a string splitting function like SPLIT_PART in postgres

Martin PreissFeb 23 2015 — edited Jan 11 2016

In postgres there is a simple string function SPLIT_PART to get the n-th part of a given string that is splitted on defined delimiters. A simple example would be:

SELECT SPLIT_PART('A,B,C,D', ',', 2);

split_part

-----------

B

So the function takes an input string, splits it at the given delimiter and returns the n-th substring.

Of course it is not a very complex task to get this functionality in Oracle (using a combination of instr, substr; maybe embetted in a user-defined function) - but I think it would be nice to get this task done with a single built-in function. This would make some common csv-import tasks very convenient.

As Frank Kulash mentioned in his comment: an (optional) enclosing character would make such a function even more valuable.

Comments
Post Details
Added on Feb 23 2015
14 comments
23,031 views