2

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?

2
  • I was trying REGEX_LIKE SELECT 1 FROM dual WHERE regexp_like ('Ankur123', '^Ankur[:digit:]$'); Commented Sep 30, 2011 at 7:00
  • This does not work, as I believe REGEX_ functions only expect wild card characters and patterns for matching and evaluating expressions. I am clueless as to how I can pass on a defined value and then specify wild card characters for a match Commented Sep 30, 2011 at 7:01

2 Answers 2

7

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.

Sign up to request clarification or add additional context in comments.

Comments

3

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.