Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reverse in Oracle this path z/y/x to x/y/z

Tags:

sql

oracle

plsql

How would I do in a SELECT query to reverse this path :

z/y/x 

for

x/y/z

where / is the delimiter and where there can be many delimiters in a single line

ex: select (... z/y/x/w/v/u ...) reversed_path from ...
like image 889
Jean-Philippe Martin Avatar asked Nov 29 '22 20:11

Jean-Philippe Martin


1 Answers

You can get your result by connecting the reverted components, then reverting the resulting string again. Just make sure you strip your starting separator and put it on the other side:

SELECT '/' || REVERSE(LTRIM(SYS_CONNECT_BY_PATH(REVERSE(x), '/'), '/') AS reversed_path
...
like image 182
knittl Avatar answered Dec 06 '22 18:12

knittl