By Jonathan Gennick, Peter Linsley
Book Price: $9.95 USD
£6.95 GBP
PDF Price: $7.99
Cover | Table of Contents
Constant widthConstant widthCREATE TABLE park (
park_name NVARCHAR2 (40),
park_phone NVARCHAR2 (15),
country VARCHAR2 (2),
description NCLOB
);
description column,
making this table an ideal platform on which to demonstrate
Oracle's regular expression capabilities.park table
and populate it with data from
http://oreilly.com/catalog/oracleregexpr.park table and identify
any park with a description containing text that looks like a phone
number. You can then use the same regular expression to extract that
phone number from the description.SELECT * FROM park WHERE park_name='Mackinac Island State Park';
Mackinac Island State Park'
isn't what most people think of when you mention the
word "pattern." The expectation is
that a pattern will use so-called metacharacters
that allow for matches when you know only the general pattern of text
you are looking for.SELECT park_name FROM park WHERE park_name LIKE '%State Park%';
%) characters in this pattern specify
that any number of characters are allowed on either side of the
string 'State Park'. Any number of characters may
be zero characters, so strings in the form 'xxx State
Park' fit the pattern. There! I've just
used a pattern to describe the operation of a pattern.DECLARE
x Boolean;
BEGIN
x := REGEXP_LIKE(
'Does this string mention Oracle?',
'Oracle');
END;
/
[]). See [ ] (Square Brackets) for more details on
this issue.\) to treat as normal a
character that would otherwise have a special meaning. For example,
to extract a dollar amount from a sentence, you might escape the
period (.) and the dollar sign
($) as follows:SELECT REGEXP_SUBSTR( 'This book costs $9.95 in the U.S.', '\$[[:digit:]]+\.[[:digit:]]+') FROM dual; $9.95
\$ in this expression requires that the
matching text begin with a dollar sign. The \.
requires a period between the two digit groups.SELECT REGEXP_SUBSTR( 'I want this \ but not this', '.*\\') FROM dual; I want this \
SELECT REGEXP_SUBSTR('\test','\test') FROM dual; test
\ has no special meaning within square
brackets ([]). When used within square brackets,
\ represents itself.\1, \2, \3,
etc. through \9 to create backreferences
to values matched by preceding subexpressions. You can backreference
up to nine subexpressions, the first nine, in any expression.
Subexpressions are numbered in the order in which their opening
parentheses are encountered when scanning from left to right.SELECT REGEXP_REPLACE( 'Sears, Andrew', '(.+), (.+)','\2 \1') FROM dual; Andrew Sears
REGEXP_INSTR(source_string, pattern [, position [, occurrence [, return_option [, match_parameter]]]])
i', 'c',
'm', or 'n') in your
match_parameter argument, which is always
the last argument of a REGEXP function call.(a' will cause this error.
Carefully check each subexpression to be sure you include both
opening and closing parentheses. Check to see whether
you've correctly escaped parentheses that do not
enclose subexpressions, and make sure you haven't
inadvertently escaped a parentheses that should open or close a
subexpression.[a' will cause this error, an expression such as
'a]' will not, because a closing (right) bracket
is treated as a regular character unless it is preceded by an opening
(left) bracket.