SQL Pattern Matching Examples - Read Me
SQL Pattern Matching Examples - Read Me
Prerequisites
Have access to Oracle Database 12c with SYS user with SYSDBA privilege and
OS authentication (so that you can execute the sqlplus / as sysdba command.)
Examples create additional tables and views within the PMUSER user schema.
Have downloaded and the SQL scripts (which is in the Scripts subdirectory of this
tutorial) into a working directory.
Navigate to your working directory and execute all files from that location.
Execute the tutorial setup which requires access to the PMUSER user.
Assumptions
This tutorial assumes the following:
1 - you have run all the associated setup scripts (contained in the Setup folder) before
trying to execute any of the SQL scripts. The SQL commands incementally add new
features and functions, however, it is not necessary to complete/run each script. Each
script works in isolation so you do need to work through an entire topic before going to
another one.
Purpose
This tutorial covers the new 12c SQL pattern matching feature. This new inter-row
pattern search capability complements the already existing capabilities of regular
expressions that match patterns within character strings of a single record. The 12c
MATCH_RECOGNIZE feature allows the definition of patterns, in terms of characters or
sets of characters, and provides the ability to search for those patterns across row
boundaries.
The PATTERN clause depends on pattern variables which means you must have a
clause to define these variables and this is done using the DEFINE clause. It is a
required clause and is used to specify the conditions that a row must meet to be
mapped to a specific pattern variable.
ONE ROW PER MATCH - each match produces one summary row and this is the
default.
ALL ROWS PER MATCH - a match spanning multiple rows will produce one
output row for each row in the match.
Setup
Set up the tutorial by running the following scripts. These scripts do not form part of the
tutorial, they create the PMUSER additional tables and views used by the scripts.
1_create_PM_user.sql
2_Setup_ticker_table.sql
3_Setup_sessionization.sql
Exercises
There is an additional readme.md file in the "Scripts" directory that will provide you with
more information about how to run each set of examples.