PATTERN
PATTERN in SQL is a part of the MATCH_RECOGNIZE clause used primarily in analyzing row sequences. It enables the detection of complex patterns within a data set by defining a regular expression pattern. Rows of the data set are evaluated against this pattern, facilitating the recognition of trends or anomalies in the data.
Example
Output
Explanation
In this example, the LIKE
pattern search is used in the WHERE clause to find all employees whose names contain the substring ‘son’. The ’%’ sign is used on both sides of ‘son’ to match any number of characters before and after ‘son’. As a result, it matches ‘Johnson Smith’ and ‘Samantha Watson’ from the ‘Employees’ table.
Example
Output
Explanation
This SQL query selects the titles and descriptions of all films in films
where the title begins with ‘Star’. The results are ordered alphabetically by title.
Example
Output
Explanation
The given example code selects all records from the ‘employee’ table where the ‘name’ field starts with ‘Ma’. Regular expressions are used, and ’^’ signifies the beginning of the string. Therefore, this will return any employee who’s name starts with ‘Ma’.