Oracle SQL Regexp_replace matching

家住魔仙堡 提交于 2019-12-06 09:58:23

问题


Here is a funky matching that I need to accomplish.

A5.1.9.11.2

Needs to become:

A05.01.09.11.02

The amount of DOT sections will vary from none to many. And the letter "A" will always be there and always be 1 character.

I would like to use the regexp_replace() function in order to use this as a sorting mechanism. Thanks.


回答1:


Oracle SQL doesn't support lookaround assertions, which would be useful for this case:

s/([0-9](?<![0-9]))/0\1/g

You'll have to use at least two replacements:

REGEXP_REPLACE(REGEXP_REPLACE(col, '([0-9]+)', '0\1'), '0([0-9]{2})', '\1')


来源:https://stackoverflow.com/questions/12584261/oracle-sql-regexp-replace-matching

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!