开发者

Oracle REGEX functions

I am working on Oracle 10gR2.

I am working on a column which stores username. Let's say that one of the values in this column is "Ankur". I want to fetch all records where username is a concatenated string of开发者_运维问答 "Ankur" followed by some numerical digits, like "Ankur1", "Ankur2", "Ankur345" and so on. I do not want to get records with values such as "Ankurab1" - that is anything which is concatenation of some characters to my input string.

I tried to use REGEX functions to achieve the desired result, but am not able to.

I was trying:

SELECT 1 FROM dual WHERE regexp_like ('Ankur123', '^Ankur[:digit:]$');

Can anyone help me here?


Oracle uses POSIX EREs (which don't support the common \d shorthand), so you can use

^Ankur[0-9]+$

Your version would nearly have worked, too:

^Ankur[[:digit:]]+$

One set of [...] for the character class, and one for the [:digit:] subset. And of course a + to allow more than just one digit.


You were close

Try regexp_like ('Ankur123', '^Ankur[[:digit:]]+$') instead.

Note the [[ instead of the single [ and the + in front of the $.

Without the + the regexp only matches for exactly one digit after the String Ankur.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜