WELCOME, GUEST
Search in Topic Titles
Welcome to Knowledge Xpert for Oracle
Knowledge Xpert for Oracle Administration
Knowledge Xpert for PL/SQL Development
PL/SQL Effective Coding Style
PL/SQL Coding Best Practices
Software Development with Oracle
PL/SQL Language Elements
Introduction to PL/SQL
Language Elements
CASE Statement and Expression
Labels
Data Manipulation Language
Exceptions and Error Handling
External Procedures
Invoker Rights
Literals
Loops
Modules
Native Dynamic SQL
Packages
PL/SQL Data Types
Pragmas
Procedures and Functions
Pseudo Columns
Regular Expressions
Regex Functions
REGEXP_INSTR Function
REGEXP_LIKE Function
REGEXP_REPLACE Function
REGEXP_SUBSTR Function
Regular Expressions Overview & Metacharacters
Regex Match Modifiers
SELECT
Transaction Management
Triggers
Variables
Views
Application Context
Autonomous Transactions
Blocks
BULK Operations
Character Sets
Collections
Conditional & Sequential Control
Continue
Cursors
Language Elements Syntax
Security
Web Development
Reference Tools
Disclaimer
Knowledge Xpert Feedback

REGEXP_SUBSTR Function

The REGEXP_SUBSTR function returns the portion of the search string that matches the regular expression pattern. The parameter names below are those used in the package STANDARD, thus can be used in your PL/SQL programs with named notation calling style.

Syntax

>>──REGEXP_SUBSTR───(──srcstr─┬─,pattern──────┬─)──────><
                              ├─,position─────┤
                              ├─,occurrence───┤
                              └─,modifier─────┘

Click on each parameter in BLUE for an explanation of its use...

For the example, look in the sh.customers table in the standard sample schemas. The sample schemas are demonstration objects that ship with Oracle 9i and later. They are installed in the seed database and are available for installation in any other database. If you do not have the sample schemas installed in your database, you or your DBA can install them using the Database Configuration Assistant or manually with the $ORACLE_HOME/demo/schema/mk_sample.sql script.

We are interested in the street number of the customers who are in Chicago. The street number is the leading digits in the street address. A regular expression is used to match the leading numbers and the REGEXP_SUBSTR function to extract this patter from the column..

SELECT cust_first_name, cust_last_name
      ,REGEXP_SUBSTR(cust_street_address,'^[[:digit:]]*')
FROM sh.customers 
WHERE REGEXP_LIKE(cust_main_phone_number
                 ,'^(\(?312\)?|\(?773\)?)')

In the example above, the street number was identified as the zero or more digit characters that appear at the beginning of the search string. See Regular Expression Metacharacters for full details on constructing expressions.

Rating (Votes: 0)

Note: Only Registered Users may rate topics.