Caio César
Caio César

Reputation: 3

Changing position of characters in a string separated by commas

I have the following string, separated by commas and ";" must reverse the comma separated values ​​of all string delimited by ";".

Example:

-7.820420745913251,-38.221914235592905;-7.838209448558699,-38.206725420257172;-7.90608019095979,-38.238334576496392;-7.905396010088811,-38.163485189211315;-7.929205504398873,-38.168137619133972;-7.940015562160337,-38.155001346411183;-7.940973415379707,-38.154590837888591;-7.941520760076489,-38.154180329366007;

Result:

-38.221914235592905,-7.820420745913251;-38.206725420257172,-7.838209448558699;...

Help me, please!!

Upvotes: 0

Views: 158

Answers (1)

DCookie
DCookie

Reputation: 43533

Try this:

SELECT regexp_replace(
'-7.820420745913251,-38.221914235592905;-7.838209448558699,-38.206725420257172;-7.90608019095979,-38.238334576496392;-7.905396010088811,-38.163485189211315;-7.929205504398873,-38.168137619133972;-7.940015562160337,-38.155001346411183;-7.940973415379707,-38.154590837888591;-7.941520760076489,-38.154180329366007;',
'([^,]*),([^;]*);','\2,\1;') RESULT
  FROM dual;

RESULT
--------------------------------------------------------------------------------
-38.221914235592905,-7.820420745913251;-38.206725420257172,-7.838209448558699;-38.238334576496392,-7.90608019095979;-38.163485189211315,-7.905396010088811;-38.168137619133972,-7.929205504398873;-38.155001346411183,-7.940015562160337;-38.154590837888591,-7.940973415379707;-38.154180329366007,-7.941520760076489;

See the REGEXP_REPLACE documentation for more information.

Upvotes: 1

Related Questions