One of the most exciting SQL features in Oracle Database 10g is support for regular expressions. Open source databases such as MySQL and PostgreSQL have supported regular expressions for years. Frankly, we were tired of having that thrown in our faces, of feeling one-upped by the open source competition. In the Oracle Database 10g release, Oracle has implemented regular expression support with a vengeance. We were surprised and delighted at what we found. You will be, too.
Regular expressions provide a syntax to describe patterns in text. Being able to describe a passage of text gives you power, the power to manipulate that text in ways that would otherwise be impossible. For example, regular expressions enable you to easily perform an operation such as the following:
Find all apparent phone numbers in a free-text, comment column, and reformat those numbers, at least the U.S. and Canadian numbers, so that all appear in the form: (999) 999-9999.
By the end of this chapter, we’ll have shown you exactly how to implement this directive. For now, we want to familiarize you with some elementary regular expression syntax.
The most basic regular expression
metacharacter is probably the period (.). Use it
to match any single character, except for the newline (usually
chr(10)). For example, assume that users of our book’s example database have taken to entering employee address and phone number ...