Вы находитесь на странице: 1из 10

Let us Understand Regular Expressions in Oracle

Database

Regular Expressions Provide A Means of Identifying A


Pattern Within A Body of Text.
A Pattern Describes What is The Actual Text We Have To
Identify Actually Looks Like.
The Pattern Can Be Something Which Can Describe Any
Three-Letter Word To Something Quite Complex, Like An
Email Address.
Oracle Regular Expressions Provide A Simple And
Powerful Mechanism For Rapidly Describing Patterns.
Regular Expressions Simplifies The Way in Which We
Search, Extract, Format, And Manipulate Text in The
Database.
Regular Expressions Are Fueled By Web Based
Technologies And The Need To Manipulate Text Data
Coming From And Going To The Browser.
Pattern Matching With Regular Expressions Can Be
Applied To All Kinds of Real Word Problems.
Regular
Expressions
Are
Used
Heavily
in
Web
Applications To Verify, Parse, Manipulate, And Format
Data Coming To And From The Middle Tier.
Large Amount of Middle Tier Processing is Taken Up With
String Processing Depending on Regular Expressions.

Traditional Database Pattern Matching


A Simple Form of Pattern Matching is Implemented Using The
LIKE Operator.
LIKE Operator Provides Two Variants of Wildcards
1. % Which Considers Zero OR More of Any Characters.
2. _ Which Considers Any Single Character At That Position.
LIKE Operator Limits The Means To Perform More Complex
Pattern Matching in Queries.
The Remedy For The Limitation of LIKE Operator is To Construct
Complex SQL OR PL/SQL Logic, Which is Hard And Difficult To
Maintain, And Consumes Hours of Development Time.
The Alternate For LIKE Operator Was A Simple PL/SQL Pattern
Matching Package Called OWA_PATTERN.
OWA_PATTERN Package Does Not Support Several Key
Required Features in Pattern Matching Such As Alternation, The
OR Condition Which Allows Matching of Either of Two
Expressions.
Creating User-Defined Functions in PL/SQL Can Be A Temporary
Solution But This Approach Has Many Limitations And Issues
Callouts Are Difficult To Develop, Deploy And Maintain
Many Times, it is Difficult For The Vendor To Support
User-Defined Functions Are Not Native To The Database Hence
Callout Solutions Are Rarely Able To Inherit Database Features
Such As Locale Support And Performance Enhancements.

Oracle Regular Expressions


Oracle Regular Expressions Are Provided From 10g Onwards
And Are Built on The Limitations of Existing Solutions.
Oracle Regular Expressions Provide A Sophisticated Set of
Meta-Characters For Describing More Complex Patterns Than
Previously Possible.
All The Meta-Characters Are Native To The Oracle Database
Hence Can Be Enhanced Version By Version And Inherits The
Changes Through Versions OR Editions.
The Oracle Regular Expressions Leverage Their Power And
Make An Application To Run More Efficiently With Improved
Data Flow And Are More Robust.
Oracle Regular Expressions Bring The Database Closer To The
Internet By Providing Enhanced String Manipulation Features
Directly Within The Database.
Oracle Regular Expressions Provide The Flexibility To Perform
Regular Expression Based String Manipulation At Any Tier in
The Application Development.
Oracle Regular Expressions Can Be Used in Any Data
Manipulation Scenario Such As
Inserting The Data into The Database
Updating The Data in The Database
Deleting The Data From The Database
Selecting The Data From The Database

What Are Regular Expressions As Per Oracle?


Regular Expressions Are Like A Language, OR Syntax,
Which Can Be Used To Describe Patterns in Text.
Regular Expressions Comprises One OR More Character
Literals AND/OR Meta-Characters.
Meta-Characters Provide Algorithmic Instructions To
Specify How Oracle Should Process The Characters That
Make Up A Regular Expression.
Where We Can Use Regular Expressions?
Validate Formats While Implementing The Constraints
Which Consist of Very Complicated Patterns of
Phone Numbers
Zip Codes
Email Addresses
Social Security Numbers
IP Addresses
Filenames And Pathnames
Search And Locate Patterns in Existing Data OR Literals
HTML Tags
Numbers
Dates
Anything That Fits Any Pattern in Any Textual Data

Interfaces Provided By Oracle in Regular Expressions


REGEXP_LIKE
Determines Whether A Pattern Matches OR Not
REGEXP_SUBSTR
Determines What String Matches The Pattern
REGEXP_INSTR
Determines Where The Match Occurred in The String
REGEXP_REPLACE
Searches And Replaces A Pattern hat Matched
REGEXP_COUNT
Count's The Occurrences Based on A Regular Expression
POSIX Extended Regular Expressions
POSIX Stands For Portable Operating System Interface For UniX
Which Was Provided First Time on Unix Platforms.
POSIX Helps Determining The Type of Character We Are
Looking For in A Pattern of Text Literal OR Database, The Type
of Character Can Be
An Alphabetic Character
A Numeric Character
A Punctuation Character
A Special Character
POSIX Character List Must Be Enclosed By Indicating Through
Square Brackets ([]).

General Information About The Regular Expressions Before


We Begin

Anchoring Characters
Character Class

Description

Anchor The Expression To The Start of A Line

Anchor The Expression To The End of A Line

Equivalence Classes
Character Class

Description

==

Oracle Supports The Equivalence Classes Through The


POSIX '[==]' Syntax.
A Base Letter And All of its Accented Versions Constitute
An Equivalence Class.
The Equivalence Classes Are Valid Only Inside The
Bracketed Expression.

Match Options
Character Class

Description

Case Sensitive Matching

Case Insensitive Matching

Treat Source String As Multi-Line Activating Anchor


Characters

Allow The Period (.) To Match Any Newline Character

m
n

POSIX Characters
Character Class

Description

[:alnum:]

Identifies Alphanumeric Characters

[:alpha:]

Identifies Alphabetic characters

[:blank:]

Identifies Blank Space Characters

[:cntrl:]

Identifies Control Characters (Non-Printing)

[:digit:]

Identifies Numeric Digits

Identifies Any [:punct:],


[:digit:] Characters

[:lower:]

Identifies Lowercase Alphabetic Characters

[:print:]

Identifies Printable Characters

[:punct:]

Punctuation Characters

Identifies Space Characters (Non-Printing), Such As


Carriage Return, Newline, Vertical Tab, And Form Feed

[:upper:]

Identifies Uppercase Alphabetic Characters

[:xdigit:]

Identifies Hexidecimal characters

[:graph:]

[:space:]

[:upper:],

[:lower:],

And

Quantifier Characters
Character Class

Description

Match 0 OR More Times

Match 0 OR 1 Time

Match 1 OR More Times

{m}

Match Exactly m Times

{m,}

Match At Least m Times

{m, n}

Match At Least m Times But Not More Than n Times

Cause The Previous Expression To Be Repeated n


Times

\n

Alternative Matching And Grouping Characters


Character Class
|
()

[char]

Description

Separates Alternates,
Operator ()

Often

Used

With

Grouping

Groups Sub-Expression into A Unit For Alternations, For


Quantifiers, OR For Back-Referencing.

Indicates A Character List, Most Meta-Characters Inside


A Character List Are Understood As Literals, With The
Exception of Character Classes, And The ^ And
Meta-Characters

Вам также может понравиться