SlideShare a Scribd company logo
1 of 11
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

What's hot (20)

Basics of pointer, pointer expressions, pointer to pointer and pointer in fun...
Basics of pointer, pointer expressions, pointer to pointer and pointer in fun...Basics of pointer, pointer expressions, pointer to pointer and pointer in fun...
Basics of pointer, pointer expressions, pointer to pointer and pointer in fun...
 
C# Strings
C# StringsC# Strings
C# Strings
 
Modules in Python Programming
Modules in Python ProgrammingModules in Python Programming
Modules in Python Programming
 
Array and string
Array and stringArray and string
Array and string
 
Java operators
Java operatorsJava operators
Java operators
 
Python : Data Types
Python : Data TypesPython : Data Types
Python : Data Types
 
Python programming : Strings
Python programming : StringsPython programming : Strings
Python programming : Strings
 
String functions and operations
String functions and operations String functions and operations
String functions and operations
 
List,tuple,dictionary
List,tuple,dictionaryList,tuple,dictionary
List,tuple,dictionary
 
358 33 powerpoint-slides_3-pointers_chapter-3
358 33 powerpoint-slides_3-pointers_chapter-3358 33 powerpoint-slides_3-pointers_chapter-3
358 33 powerpoint-slides_3-pointers_chapter-3
 
SQL BUILT-IN FUNCTION
SQL BUILT-IN FUNCTIONSQL BUILT-IN FUNCTION
SQL BUILT-IN FUNCTION
 
Manipulators in c++
Manipulators in c++Manipulators in c++
Manipulators in c++
 
Functions in C
Functions in CFunctions in C
Functions in C
 
Python programming : Classes objects
Python programming : Classes objectsPython programming : Classes objects
Python programming : Classes objects
 
Python-01| Fundamentals
Python-01| FundamentalsPython-01| Fundamentals
Python-01| Fundamentals
 
Dynamic memory allocation in c++
Dynamic memory allocation in c++Dynamic memory allocation in c++
Dynamic memory allocation in c++
 
Strings in Java
Strings in JavaStrings in Java
Strings in Java
 
Inheritance and Polymorphism Java
Inheritance and Polymorphism JavaInheritance and Polymorphism Java
Inheritance and Polymorphism Java
 
Python set
Python setPython set
Python set
 
Preprocessor
PreprocessorPreprocessor
Preprocessor
 

Similar to 11. using regular expressions with oracle database

SQL for pattern matching (Oracle 12c)
SQL for pattern matching (Oracle 12c)SQL for pattern matching (Oracle 12c)
SQL for pattern matching (Oracle 12c)Logan Palanisamy
 
Regular expressions in Python
Regular expressions in PythonRegular expressions in Python
Regular expressions in PythonSujith Kumar
 
unit-4 regular expression.pptx
unit-4 regular expression.pptxunit-4 regular expression.pptx
unit-4 regular expression.pptxPadreBhoj
 
regex.pptx
regex.pptxregex.pptx
regex.pptxqnuslv
 
Module 3 - Regular Expressions, Dictionaries.pdf
Module 3 - Regular  Expressions,  Dictionaries.pdfModule 3 - Regular  Expressions,  Dictionaries.pdf
Module 3 - Regular Expressions, Dictionaries.pdfGaneshRaghu4
 
Strings Arrays
Strings ArraysStrings Arrays
Strings Arraysphanleson
 
Unit 2 - Regular Expression.pptx
Unit 2 - Regular Expression.pptxUnit 2 - Regular Expression.pptx
Unit 2 - Regular Expression.pptxmythili213835
 
Unit 2 - Regular Expression .pptx
Unit 2 - Regular        Expression .pptxUnit 2 - Regular        Expression .pptx
Unit 2 - Regular Expression .pptxmythili213835
 
Python - Regular Expressions
Python - Regular ExpressionsPython - Regular Expressions
Python - Regular ExpressionsMukesh Tekwani
 
Regular_Expressions.pptx
Regular_Expressions.pptxRegular_Expressions.pptx
Regular_Expressions.pptxDurgaNayak4
 
Regular expressionfunction
Regular expressionfunctionRegular expressionfunction
Regular expressionfunctionADARSH BHATT
 
Python regular expressions
Python regular expressionsPython regular expressions
Python regular expressionsKrishna Nanda
 
Java: Regular Expression
Java: Regular ExpressionJava: Regular Expression
Java: Regular ExpressionMasudul Haque
 

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

Les08
Les08Les08
Les08
 
Adv. python regular expression by Rj
Adv. python regular expression by RjAdv. python regular expression by Rj
Adv. python regular expression by Rj
 
SQL for pattern matching (Oracle 12c)
SQL for pattern matching (Oracle 12c)SQL for pattern matching (Oracle 12c)
SQL for pattern matching (Oracle 12c)
 
Regular expressions in Python
Regular expressions in PythonRegular expressions in Python
Regular expressions in Python
 
unit-4 regular expression.pptx
unit-4 regular expression.pptxunit-4 regular expression.pptx
unit-4 regular expression.pptx
 
PHP Web Programming
PHP Web ProgrammingPHP Web Programming
PHP Web Programming
 
regex.pptx
regex.pptxregex.pptx
regex.pptx
 
Php, mysqlpart2
Php, mysqlpart2Php, mysqlpart2
Php, mysqlpart2
 
Module 3 - Regular Expressions, Dictionaries.pdf
Module 3 - Regular  Expressions,  Dictionaries.pdfModule 3 - Regular  Expressions,  Dictionaries.pdf
Module 3 - Regular Expressions, Dictionaries.pdf
 
Strings Arrays
Strings ArraysStrings Arrays
Strings Arrays
 
Andrei's Regex Clinic
Andrei's Regex ClinicAndrei's Regex Clinic
Andrei's Regex Clinic
 
Unit 2 - Regular Expression.pptx
Unit 2 - Regular Expression.pptxUnit 2 - Regular Expression.pptx
Unit 2 - Regular Expression.pptx
 
Unit 2 - Regular Expression .pptx
Unit 2 - Regular        Expression .pptxUnit 2 - Regular        Expression .pptx
Unit 2 - Regular Expression .pptx
 
Python - Regular Expressions
Python - Regular ExpressionsPython - Regular Expressions
Python - Regular Expressions
 
Regular_Expressions.pptx
Regular_Expressions.pptxRegular_Expressions.pptx
Regular_Expressions.pptx
 
Regular expressionfunction
Regular expressionfunctionRegular expressionfunction
Regular expressionfunction
 
Python regular expressions
Python regular expressionsPython regular expressions
Python regular expressions
 
Python strings
Python stringsPython strings
Python strings
 
Java: Regular Expression
Java: Regular ExpressionJava: Regular Expression
Java: Regular Expression
 
Regex1.1.pptx
Regex1.1.pptxRegex1.1.pptx
Regex1.1.pptx
 

More from Amrit Kaur

File Organization
File OrganizationFile Organization
File OrganizationAmrit Kaur
 
Introduction to transaction processing
Introduction to transaction processingIntroduction to transaction processing
Introduction to transaction processingAmrit Kaur
 
Transaction Processing
Transaction ProcessingTransaction Processing
Transaction ProcessingAmrit Kaur
 
Sample Interview Question
Sample Interview QuestionSample Interview Question
Sample Interview QuestionAmrit Kaur
 
12. oracle database architecture
12. oracle database architecture12. oracle database architecture
12. oracle database architectureAmrit Kaur
 
9. index and index organized table
9. index and index organized table9. index and index organized table
9. index and index organized tableAmrit Kaur
 
8. transactions
8. transactions8. transactions
8. transactionsAmrit Kaur
 
7. exceptions handling in pl
7. exceptions handling in pl7. exceptions handling in pl
7. exceptions handling in plAmrit Kaur
 
5. stored procedure and functions
5. stored procedure and functions5. stored procedure and functions
5. stored procedure and functionsAmrit Kaur
 
2. DML_INSERT_DELETE_UPDATE
2. DML_INSERT_DELETE_UPDATE2. DML_INSERT_DELETE_UPDATE
2. DML_INSERT_DELETE_UPDATEAmrit Kaur
 
1. dml select statement reterive data
1. dml select statement reterive data1. dml select statement reterive data
1. dml select statement reterive dataAmrit Kaur
 
Chapter 8 Inheritance
Chapter 8 InheritanceChapter 8 Inheritance
Chapter 8 InheritanceAmrit Kaur
 
Chapter 7 C++ As OOP
Chapter 7 C++ As OOPChapter 7 C++ As OOP
Chapter 7 C++ As OOPAmrit Kaur
 
Chapter 6 OOPS Concept
Chapter 6 OOPS ConceptChapter 6 OOPS Concept
Chapter 6 OOPS ConceptAmrit Kaur
 

More from Amrit Kaur (20)

File Organization
File OrganizationFile Organization
File Organization
 
Introduction to transaction processing
Introduction to transaction processingIntroduction to transaction processing
Introduction to transaction processing
 
ER diagram
ER diagramER diagram
ER diagram
 
Transaction Processing
Transaction ProcessingTransaction Processing
Transaction Processing
 
Normalization
NormalizationNormalization
Normalization
 
Sample Interview Question
Sample Interview QuestionSample Interview Question
Sample Interview Question
 
12. oracle database architecture
12. oracle database architecture12. oracle database architecture
12. oracle database architecture
 
10. timestamp
10. timestamp10. timestamp
10. timestamp
 
9. index and index organized table
9. index and index organized table9. index and index organized table
9. index and index organized table
 
8. transactions
8. transactions8. transactions
8. transactions
 
7. exceptions handling in pl
7. exceptions handling in pl7. exceptions handling in pl
7. exceptions handling in pl
 
6. triggers
6. triggers6. triggers
6. triggers
 
5. stored procedure and functions
5. stored procedure and functions5. stored procedure and functions
5. stored procedure and functions
 
4. plsql
4. plsql4. plsql
4. plsql
 
3. ddl create
3. ddl create3. ddl create
3. ddl create
 
2. DML_INSERT_DELETE_UPDATE
2. DML_INSERT_DELETE_UPDATE2. DML_INSERT_DELETE_UPDATE
2. DML_INSERT_DELETE_UPDATE
 
1. dml select statement reterive data
1. dml select statement reterive data1. dml select statement reterive data
1. dml select statement reterive data
 
Chapter 8 Inheritance
Chapter 8 InheritanceChapter 8 Inheritance
Chapter 8 Inheritance
 
Chapter 7 C++ As OOP
Chapter 7 C++ As OOPChapter 7 C++ As OOP
Chapter 7 C++ As OOP
 
Chapter 6 OOPS Concept
Chapter 6 OOPS ConceptChapter 6 OOPS Concept
Chapter 6 OOPS Concept
 

Recently uploaded

Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfDr Vijay Vishwakarma
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17Celine George
 
Plant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptxPlant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptxUmeshTimilsina1
 
Philosophy of china and it's charactistics
Philosophy of china and it's charactisticsPhilosophy of china and it's charactistics
Philosophy of china and it's charactisticshameyhk98
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...Poonam Aher Patil
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsKarakKing
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the ClassroomPooky Knightsmith
 
Tatlong Kwento ni Lola basyang-1.pdf arts
Tatlong Kwento ni Lola basyang-1.pdf artsTatlong Kwento ni Lola basyang-1.pdf arts
Tatlong Kwento ni Lola basyang-1.pdf artsNbelano25
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and ModificationsMJDuyan
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfNirmal Dwivedi
 
21st_Century_Skills_Framework_Final_Presentation_2.pptx
21st_Century_Skills_Framework_Final_Presentation_2.pptx21st_Century_Skills_Framework_Final_Presentation_2.pptx
21st_Century_Skills_Framework_Final_Presentation_2.pptxJoelynRubio1
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structuredhanjurrannsibayan2
 
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...Amil baba
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxJisc
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024Elizabeth Walsh
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxDr. Ravikiran H M Gowda
 
OSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsOSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsSandeep D Chaudhary
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...pradhanghanshyam7136
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxEsquimalt MFRC
 

Recently uploaded (20)

Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
Plant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptxPlant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptx
 
Philosophy of china and it's charactistics
Philosophy of china and it's charactisticsPhilosophy of china and it's charactistics
Philosophy of china and it's charactistics
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the Classroom
 
Tatlong Kwento ni Lola basyang-1.pdf arts
Tatlong Kwento ni Lola basyang-1.pdf artsTatlong Kwento ni Lola basyang-1.pdf arts
Tatlong Kwento ni Lola basyang-1.pdf arts
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
21st_Century_Skills_Framework_Final_Presentation_2.pptx
21st_Century_Skills_Framework_Final_Presentation_2.pptx21st_Century_Skills_Framework_Final_Presentation_2.pptx
21st_Century_Skills_Framework_Final_Presentation_2.pptx
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structure
 
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptx
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptx
 
OSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsOSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & Systems
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 

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;