Database Reference
In-Depth Information
11.2 In-Database Text Analysis
SQL offers several basic text string functions as well as wildcard search
functionality. Related SELECT statements and their results enclosed in the SQL
comment delimiters, /**/ , include the following:
SELECT SUBSTRING('1234567890', 3,2) /* returns '34' */
SELECT '1234567890' LIKE '%7%' /* returns True */
SELECT '1234567890' LIKE '7%' /* returns False */
SELECT '1234567890' LIKE '_2%' /* returns True */
SELECT '1234567890' LIKE '_3%' /* returns False */
SELECT '1234567890' LIKE '__3%' /* returns True */
This section examines more dynamic and flexible tools for text analysis, called
regular expressions, and their use in SQL queries to perform pattern matching.
Table 11.1 includes several forms of the comparison operator used with regular
expressions and related SQL examples that produce a True result.
Table 11.1 Regular Expression Operators
Operator Description
Example
Contains the regular expression (case sensitive) '123a567' ˜
'a'
˜
Contains the regular expression (case insensitive) '123a567' ˜*
'A'
˜*
Does not contain the regular expression (case
sensitive)
'123a567' !˜
'A'
Does not contain the regular expression (case
insensitive)
!˜*
'123a567' !˜*
'b'
More complex forms of the patterns that are specified at the RHS of the comparison
operator can be constructed by using the elements in Table 11.2 .
Search WWH ::




Custom Search