SlideShare a Scribd company logo
4
Most read
6
Most read
8
Most read
Using Regular Expressions With
Oracle Database
• The database provides a set of SQL functions
that allow you to search and manipulate
strings using regular expressions.
• Apply on datatype that holds character data .
• A regular expression is specified using two
types of characters:
– Meta characters
• operators that specify algorithms
– Literals
• the actual characters to search for.
SQL Regular Expression Function
Returns the number of times a pattern match is found
in an input sting
REGEXP_COUNT
Similar to the LIKE operator, but performs regular
expression matching instead of simple pattern
matching (condition)
REGEXP_LIKE
REGEXP_SUBSTR
REGEXP_INSTR
REGEXP_REPLACE Searches for a regular expression pattern and
replaces it with a replacement string
Searches for a regular expression pattern within a
given string and extracts the matched substring
Searches a string for a regular expression pattern and
returns the position where the match is found
DescriptionFunction or Condition
Name
What are Metacharacters?
• Metacharacters are special characters that
have a special meaning such as
– a wildcard,
– a repeating character,
– a nonmatching character,
– or a range of characters.
• You can use several predefined metacharacter
symbols in the pattern matching.
Using Metacharacters
Metacharcater Operator Name Description
. Any Character -- Dot Matches any character
+ One or More -- Plus
Quantifier
Matches one or more occurrences of the
preceding subexpression
? Zero or One -- Question Mark
Quantifier
Matches zero or one occurrence of the preceding
subexpression
* Zero or More -- Star
Quantifier
Matches zero or more occurrences of the
preceding subexpression
{m} Interval--Exact Count Matches exactlym occurrences of the preceding
subexpression
{m,} Interval--At Least Count Matches at least m occurrences of the preceding
subexpression
{m,n} Interval--Between Count Matches at least m, but not more
than n occurrences of the preceding
subexpression
[ ... ] Matching Character List Matches any character in list ...
[^ ... ] Non-Matching Character List Matches any character not in list ...
Using Metacharacters
Metacharcater Operator Name Description
| Or 'a|b' matches character 'a' or 'b'.
( ... ) Subexpression or Grouping Treat expression ... as a unit. The subexpression
can be a string of literals or a complex expression
containing operators.
n Backreference Matches the nth preceding subexpression,
where n is an integer from 1 to 9.
 Escape Character Treat the subsequent metacharacter in the
expression as a literal.
^ Beginning of Line Anchor Match the subsequent expression only when it
occurs at the beginning of a line.
$ End of Line Anchor Match the preceding expression only when it
occurs at the end of a line.
Regular Expression Function Syntax
REGEXP_LIKE (source_char, pattern [,match_option]
REGEXP_INSTR (source_char, pattern [, position
[, occurrence [, return_option
[, match_option [, subexpr]]]]])
REGEXP_SUBSTR (source_char, pattern [, position
[, occurrence [, match_option
[, subexpr]]]])
REGEXP_REPLACE(source_char, pattern [,replacestr
[, position [, occurrence
[, match_option]]]])
REGEXP_COUNT (source_char, pattern [, position
[, occurrence [, match_option]]])
Regular Expression Function Syntax
• match_options is a text literal that lets you change
the default matching behavior of the function.
– 'i' specifies case-insensitive matching.
– 'c' specifies case-sensitive matching.
– 'n' allows the period (.), to match the newline character.
– 'm' treats the source string as multiple lines
Examples
• Display details of employees whose first name is Steven or Stephen
(where first_name begins with Ste and ends with en and in between is
either v or ph)
SELECT first_name, last_name
FROM employees
WHERE REGEXP_LIKE (first_name, '^Ste(v|ph)en$');
• Last name for those employees with a double vowel in their last name
SELECT last_name
FROM employees
WHERE REGEXP_LIKE (last_name, '([aeiou])1', 'i');
Examples
• examines phone_number, looking for the pattern xxx.xxx.xxxx.
Oracle reformats this pattern with (xxx) xxx-xxxx.
SELECT REGEXP_REPLACE(phone_number,
'([[:digit:]]{3}).([[:digit:]]{3}).([[:digit:]]{4})‘,
'(1) 2-3') "REGEXP_REPLACE“ FROM employees;
• looking for http:// followed by a substring of one or more
alphanumeric characters and optionally, a period (.).
SELECT REGEXP_SUBSTR('http://www.oracle.com/products',
'http://([[:alnum:]]+.?){3,4}/?') "REGEXP_SUBSTR"
FROM DUAL;

More Related Content

PPSX
Regular expressions in oracle
PPT
Data flow diagram(19th march)
PPT
Database systems introduction
PPT
Configuration management
PPT
Requirement analysis and specification, software engineering
PPTX
Postgresql stored procedure
PPTX
Sqlmap
PPT
Data integrity
Regular expressions in oracle
Data flow diagram(19th march)
Database systems introduction
Configuration management
Requirement analysis and specification, software engineering
Postgresql stored procedure
Sqlmap
Data integrity

What's hot (20)

PPTX
Sequence diagram
PPTX
Data Modeling PPT
PPT
12. Indexing and Hashing in DBMS
ODP
Ms sql-server
PPTX
PostgreSQL Database Slides
DOC
Data warehouse-dimensional-modeling-and-design
PPTX
Online analytical processing
PPTX
PDF
Training Series: Build APIs with Neo4j GraphQL Library
PPT
ER-Model-ER Diagram
PPTX
Data Modeling Basics
PPT
MySQL Functions
PPTX
Non functional requirements. do we really care…?
PPT
Data models
PPTX
Chapter 6 relational data model and relational
PPT
OLAP
PPTX
Relational algebra ppt
PPTX
PLSQL Tutorial
PDF
Cassandra techniques de modelisation avancee
PDF
Query optimization in SQL
Sequence diagram
Data Modeling PPT
12. Indexing and Hashing in DBMS
Ms sql-server
PostgreSQL Database Slides
Data warehouse-dimensional-modeling-and-design
Online analytical processing
Training Series: Build APIs with Neo4j GraphQL Library
ER-Model-ER Diagram
Data Modeling Basics
MySQL Functions
Non functional requirements. do we really care…?
Data models
Chapter 6 relational data model and relational
OLAP
Relational algebra ppt
PLSQL Tutorial
Cassandra techniques de modelisation avancee
Query optimization in SQL
Ad

Similar to 11. using regular expressions with oracle database (20)

PPTX
Regular Expressions 101 Introduction to Regular Expressions
PPT
PPT
Adv. python regular expression by Rj
PPTX
SQL for pattern matching (Oracle 12c)
PPTX
Regular expressions in Python
PPTX
unit-4 regular expression.pptx
ODP
PHP Web Programming
PPTX
regex.pptx
PPT
Php, mysqlpart2
PDF
Module 3 - Regular Expressions, Dictionaries.pdf
PPTX
Regular expressions in php programming language.pptx
PPT
Strings Arrays
KEY
Andrei's Regex Clinic
PPTX
Unit 2 - Regular Expression.pptx
PPTX
Unit 2 - Regular Expression .pptx
DOCX
Python - Regular Expressions
PPTX
Regular_Expressions.pptx
DOCX
Regular expressionfunction
PDF
Python regular expressions
PPTX
22CS307-ADAVANCE JAVA PROGRAMMING UNIT 5
Regular Expressions 101 Introduction to Regular Expressions
Adv. python regular expression by Rj
SQL for pattern matching (Oracle 12c)
Regular expressions in Python
unit-4 regular expression.pptx
PHP Web Programming
regex.pptx
Php, mysqlpart2
Module 3 - Regular Expressions, Dictionaries.pdf
Regular expressions in php programming language.pptx
Strings Arrays
Andrei's Regex Clinic
Unit 2 - Regular Expression.pptx
Unit 2 - Regular Expression .pptx
Python - Regular Expressions
Regular_Expressions.pptx
Regular expressionfunction
Python regular expressions
22CS307-ADAVANCE JAVA PROGRAMMING UNIT 5
Ad

More from Amrit Kaur (20)

PDF
File Organization
PDF
Introduction to transaction processing
PDF
ER diagram
PPTX
Transaction Processing
PDF
Normalization
PDF
Sample Interview Question
PPTX
12. oracle database architecture
PPTX
10. timestamp
PPTX
9. index and index organized table
PPTX
8. transactions
PPTX
7. exceptions handling in pl
PPTX
6. triggers
PPTX
5. stored procedure and functions
PPTX
4. plsql
PPTX
3. ddl create
PPTX
2. DML_INSERT_DELETE_UPDATE
PPTX
1. dml select statement reterive data
PDF
Chapter 8 Inheritance
PDF
Chapter 7 C++ As OOP
PDF
Chapter 6 OOPS Concept
File Organization
Introduction to transaction processing
ER diagram
Transaction Processing
Normalization
Sample Interview Question
12. oracle database architecture
10. timestamp
9. index and index organized table
8. transactions
7. exceptions handling in pl
6. triggers
5. stored procedure and functions
4. plsql
3. ddl create
2. DML_INSERT_DELETE_UPDATE
1. dml select statement reterive data
Chapter 8 Inheritance
Chapter 7 C++ As OOP
Chapter 6 OOPS Concept

Recently uploaded (20)

PDF
Anesthesia in Laparoscopic Surgery in India
PDF
TR - Agricultural Crops Production NC III.pdf
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PDF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
PDF
Abdominal Access Techniques with Prof. Dr. R K Mishra
PPTX
Lesson notes of climatology university.
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PDF
Pre independence Education in Inndia.pdf
PDF
Basic Mud Logging Guide for educational purpose
PDF
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
PDF
Supply Chain Operations Speaking Notes -ICLT Program
PDF
102 student loan defaulters named and shamed – Is someone you know on the list?
PDF
RMMM.pdf make it easy to upload and study
PPTX
BOWEL ELIMINATION FACTORS AFFECTING AND TYPES
PDF
VCE English Exam - Section C Student Revision Booklet
PPTX
master seminar digital applications in india
PDF
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
PDF
O7-L3 Supply Chain Operations - ICLT Program
PPTX
Pharma ospi slides which help in ospi learning
Anesthesia in Laparoscopic Surgery in India
TR - Agricultural Crops Production NC III.pdf
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
Abdominal Access Techniques with Prof. Dr. R K Mishra
Lesson notes of climatology university.
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
Pre independence Education in Inndia.pdf
Basic Mud Logging Guide for educational purpose
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
O5-L3 Freight Transport Ops (International) V1.pdf
Supply Chain Operations Speaking Notes -ICLT Program
102 student loan defaulters named and shamed – Is someone you know on the list?
RMMM.pdf make it easy to upload and study
BOWEL ELIMINATION FACTORS AFFECTING AND TYPES
VCE English Exam - Section C Student Revision Booklet
master seminar digital applications in india
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
O7-L3 Supply Chain Operations - ICLT Program
Pharma ospi slides which help in ospi learning

11. using regular expressions with oracle database

  • 1. Using Regular Expressions With Oracle Database
  • 2. • The database provides a set of SQL functions that allow you to search and manipulate strings using regular expressions. • Apply on datatype that holds character data .
  • 3. • A regular expression is specified using two types of characters: – Meta characters • operators that specify algorithms – Literals • the actual characters to search for.
  • 4. SQL Regular Expression Function Returns the number of times a pattern match is found in an input sting REGEXP_COUNT Similar to the LIKE operator, but performs regular expression matching instead of simple pattern matching (condition) REGEXP_LIKE REGEXP_SUBSTR REGEXP_INSTR REGEXP_REPLACE Searches for a regular expression pattern and replaces it with a replacement string Searches for a regular expression pattern within a given string and extracts the matched substring Searches a string for a regular expression pattern and returns the position where the match is found DescriptionFunction or Condition Name
  • 5. What are Metacharacters? • Metacharacters are special characters that have a special meaning such as – a wildcard, – a repeating character, – a nonmatching character, – or a range of characters. • You can use several predefined metacharacter symbols in the pattern matching.
  • 6. Using Metacharacters Metacharcater Operator Name Description . Any Character -- Dot Matches any character + One or More -- Plus Quantifier Matches one or more occurrences of the preceding subexpression ? Zero or One -- Question Mark Quantifier Matches zero or one occurrence of the preceding subexpression * Zero or More -- Star Quantifier Matches zero or more occurrences of the preceding subexpression {m} Interval--Exact Count Matches exactlym occurrences of the preceding subexpression {m,} Interval--At Least Count Matches at least m occurrences of the preceding subexpression {m,n} Interval--Between Count Matches at least m, but not more than n occurrences of the preceding subexpression [ ... ] Matching Character List Matches any character in list ... [^ ... ] Non-Matching Character List Matches any character not in list ...
  • 7. Using Metacharacters Metacharcater Operator Name Description | Or 'a|b' matches character 'a' or 'b'. ( ... ) Subexpression or Grouping Treat expression ... as a unit. The subexpression can be a string of literals or a complex expression containing operators. n Backreference Matches the nth preceding subexpression, where n is an integer from 1 to 9. Escape Character Treat the subsequent metacharacter in the expression as a literal. ^ Beginning of Line Anchor Match the subsequent expression only when it occurs at the beginning of a line. $ End of Line Anchor Match the preceding expression only when it occurs at the end of a line.
  • 8. Regular Expression Function Syntax REGEXP_LIKE (source_char, pattern [,match_option] REGEXP_INSTR (source_char, pattern [, position [, occurrence [, return_option [, match_option [, subexpr]]]]]) REGEXP_SUBSTR (source_char, pattern [, position [, occurrence [, match_option [, subexpr]]]]) REGEXP_REPLACE(source_char, pattern [,replacestr [, position [, occurrence [, match_option]]]]) REGEXP_COUNT (source_char, pattern [, position [, occurrence [, match_option]]])
  • 9. Regular Expression Function Syntax • match_options is a text literal that lets you change the default matching behavior of the function. – 'i' specifies case-insensitive matching. – 'c' specifies case-sensitive matching. – 'n' allows the period (.), to match the newline character. – 'm' treats the source string as multiple lines
  • 10. Examples • Display details of employees whose first name is Steven or Stephen (where first_name begins with Ste and ends with en and in between is either v or ph) SELECT first_name, last_name FROM employees WHERE REGEXP_LIKE (first_name, '^Ste(v|ph)en$'); • Last name for those employees with a double vowel in their last name SELECT last_name FROM employees WHERE REGEXP_LIKE (last_name, '([aeiou])1', 'i');
  • 11. Examples • examines phone_number, looking for the pattern xxx.xxx.xxxx. Oracle reformats this pattern with (xxx) xxx-xxxx. SELECT REGEXP_REPLACE(phone_number, '([[:digit:]]{3}).([[:digit:]]{3}).([[:digit:]]{4})‘, '(1) 2-3') "REGEXP_REPLACE“ FROM employees; • looking for http:// followed by a substring of one or more alphanumeric characters and optionally, a period (.). SELECT REGEXP_SUBSTR('http://www.oracle.com/products', 'http://([[:alnum:]]+.?){3,4}/?') "REGEXP_SUBSTR" FROM DUAL;