Oracle Regex: Match Numbers Guide
Here is how you can use Oracle regular expressions to match numbers:
- Match using the REGEXP_LIKE function,
For example, to match an integer, you can use the following expression:
SELECT column_name
FROM table_name
WHERE REGEXP_LIKE(column_name, ‘^[0-9]+$’); - This expression can match one or more numbers, and must only be numbers, without any other characters.
- To extract numbers using the REGEXP_SUBSTR function, you can use the following expression:
SELECT REGEXP_SUBSTR(column_name, ‘[0-9]+’)
FROM table_name; - This expression can identify one or more numbers in a string and return the first one found.
- Replace non-numeric characters using the REGEXP_REPLACE function. If you want to remove non-numeric characters from a string, you can use the following expression:
SELECT REGEXP_REPLACE(column_name, ‘[^0-9]’, ‘’)
FROM table_name; - This expression will replace all non-numeric characters and only keep numeric characters.
It is important to note that Oracle’s regular expressions are based on Perl-style regular expressions, which feature some special symbols and syntax. When using regular expressions, adjustments and expansions can be made according to specific needs.