Connecting Tech Pros Worldwide Forums | Help | Site Map

10g REGULAR EXPRESSIONS (REGEXP_LIKE)

amitpatel66's Avatar
Moderator
 
Join Date: Mar 2007
Location: Hyderabad, India
Posts: 2,216
#1   Oct 9 '07
Let us have a look at the examples for each of the above mentioned SQL functions and WHERE clause operator

REGEXP_LIKE

Syntax:

REGEXP_LIKE(source_string, pattern [, match_parameter])

source_string - can be column of CHAR, VARCHAR2, CLOB, NCHAR, NVARCHAR2, and NCLOB but not LONG datatypes

pattern - the regular expression

match_parameter - allows optional parameters such as handling the newline character, retaining multiline formatting, and providing control over case-sensitivity

Example:

The following SQL query searches the ZIP column for a pattern that satisfies the regular expression [^[:digit:]]. It will retrieve those rows in the ZIPCODE table for which the ZIP column values contain any character that is not a numeric digit.

Expand|Select|Wrap|Line Numbers
  1.  
  2. SELECT zip
  3.   FROM zipcode
  4.  WHERE REGEXP_LIKE(zip, '[^[:digit:]]') 
  5.  
  6. ZIP
  7. -----
  8. ab123
  9. 123xy
  10. 007ab
  11. abcxy 
  12.  
In case if tha pattern is used as '^[[:digit:]]' then it would look for zip code starting with digits.



Closed Thread