Regular Expressions in Oracle

I need to operate on a big table with lots of records, but only on rows where the primary key starts with a number. Because obviously its a good idea to differentiate types of records in this way …. only joking! Its just one of those little tasks that crops up from time to time.

The Fast and Dirty Way

select code
from products
where substr(code,1,1) in (0,1,2,3,4,5,6,7,8,9)

Oracle Regular Expression Method

select code
from products
where regexp_like(code,'^[[:digit:]]')

Further Resources

I got this from this article on technology and also the definition of some of the character classes from this very helpful resource on psoug

Leave a Reply

Please use [code] and [/code] around any source code you wish to share.

This site uses Akismet to reduce spam. Learn how your comment data is processed.