Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How could I search for a specific pattern in a column?

For example, I like to get all user names that start with either letter A or B.

(btw: this is tagged oracle, but it might be interesting in other RDBMS as well).

share|improve this question
Perhaps the question should be re-titled since the solution does not require a regular expression. I added regular-expression as a tag. – Leigh Riffel Jan 4 '11 at 14:24
up vote 15 down vote accepted

Your question doesn't require regular expressions:

WHERE name LIKE 'A%' OR name LIKE 'B%'

For Oracle, there's REGEXP_LIKE; Postresql, there's SIMILAR TO; mysql has REGEXP. One thing to remember though is not all regular expression engines are the same, so just because they support regular expressions doesn't mean they necessarily support word boundry assertions, non-greedy quantifiers, or negative lookbehind assertions, etc.

share|improve this answer
Thanks. In my case, that will do. I also found this to work: SELECT mname FROM names WHERE regexp_like(mname,'^[AB].*$'); – Sebastian Roth Jan 4 '11 at 4:03
All you really need is ^[AB] ... the .*$ is superfluous – Joe Jan 4 '11 at 4:13

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.