Regular Expressions In SQL
Wednesday, June 11th, 2008Regular expressions are pretty easy to use, however, different DBMS’s handle them differently.
In PostgreSQL, regular expression searches are done via the “~” character. For instance:
SELECT * FROM table1 WHERE column1 ~ '^(.?)unq([a-z]{4})([1-9]+)$';
In MySQL, this is done via REGEXP:
SELECT * FROM table1 WHERE column1 REGEXP '^S([c-z])n(.*)$';
In Oracle, this is done via the REGEXP_LIKE function:
SELECT * FROM table1 WHERE REGEXP_LIKE(column1, '[[:digit:]]{2}$');
