SlideShare a Scribd company logo
1 of 61
Download to read offline
Oracle 12c
SQL Pattern Matching
Made Easy
Oren Nakdimon
www.db-oriented.com
 oren@db-oriented.com
 +972-54-4393763
@DBoriented
This presentation is available in http://db-oriented.com/presentations
©OrenNakdimon©OrenNakdimon
Which employees
are in a specific
department?
How many times
was Ben Gurion
prime minister?
Fibonacci
(again?!?)
This presentation is available in http://db-oriented.com/presentations
©OrenNakdimon©OrenNakdimon
Who Am I?
a chronology by “Oracle years”
Where: IAF
When: Oracle 6/7 [1991-1997]
What: Developer
Where: Golden Screens
When: Oracle 8 [1997-1998]
What: Server Group Manager
Where: TELEknowledge
When: Oracle 8i/9i [1998-2003]
What: DBA Group Manager
Where: Olista
When: Oracle 10g/11g [2004-2011]
What: VP R&D + Israel Site Manager
This presentation is available in http://db-oriented.com/presentations
©OrenNakdimon©OrenNakdimon
Database Architect /
Developer / DBA
Who Am I?
a chronology by “Oracle years”
This presentation is available in http://db-oriented.com/presentations
©OrenNakdimon©OrenNakdimon
@DBoriented
This presentation is available in http://db-oriented.com/presentations
©OrenNakdimon©OrenNakdimon
http://db-oriented.com
SQL Analytics Evolution
This presentation is available in http://db-oriented.com/presentations
©OrenNakdimon©OrenNakdimon
The Most Basic SQL
 Row-level visibility
 Maximum one output row per input row
 WHERE clause
This presentation is available in http://db-oriented.com/presentations
©OrenNakdimon©OrenNakdimon
Aggregate Functions
 Group-level visibility
 Strict definition of “group”
 Each input row belongs to exactly one group
 Maximum one output row per group
 GROUP BY clause
 HAVING clause
This presentation is available in http://db-oriented.com/presentations
©OrenNakdimon©OrenNakdimon
Analytic (Window) Functions
 Window-level visibility
 Strict definition of “window”
 Each input row has its own window
 Window-level aggregates are added to input rows
 OVER
 PARTITION BY
 ORDER BY
This presentation is available in http://db-oriented.com/presentations
©OrenNakdimon©OrenNakdimon
Pattern Matching
 Enhanced analysis of row sequences
 Match-based output
 One row per match (similar to the “group by” concept)
or
 All the match’s input rows (similar to the “window” concept)
 Each input row may belong to 0, 1 or more matches
This presentation is available in http://db-oriented.com/presentations
©OrenNakdimon©OrenNakdimon
Find all the employees in department 30
 The obvious solution is:
 But that is too easy ;-)
SELECT * FROM EMP WHERE DEPTNO = 30
This presentation is available in http://db-oriented.com/presentations
©OrenNakdimon©OrenNakdimon
Find all the employees in department 30
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
7369 SMITH CLERK 7902 17/12/1980 800 20
7499 ALLEN SALESMAN 7698 20/02/1981 1600 300 30
7521 WARD SALESMAN 7698 22/02/1981 1250 500 30
7566 JONES MANAGER 7839 02/04/1981 2975 20
7654 MARTIN SALESMAN 7698 28/09/1981 1250 1400 30
7698 BLAKE MANAGER 7839 01/05/1981 2850 30
7782 CLARK MANAGER 7839 09/06/1981 2450 10
7788 SCOTT ANALYST 7566 19/04/1987 3000 20
7839 KING PRESIDENT 17/11/1981 5000 10
7844 TURNER SALESMAN 7698 08/09/1981 1500 0 30
7876 ADAMS CLERK 7788 23/05/1987 1100 20
7900 JAMES CLERK 7698 03/12/1981 950 30
7902 FORD ANALYST 7566 03/12/1981 3000 20
7934 MILLER CLERK 7782 23/01/1982 1300 10
D30






Pattern
Variable
SELECT *
FROM EMP
MATCH_RECOGNIZE (
ALL ROWS PER MATCH
PATTERN (D30)
DEFINE D30 AS DEPTNO=30
)
1
2
3
4
5
6
This presentation is available in http://db-oriented.com/presentations
©OrenNakdimon©OrenNakdimon
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
7369 SMITH CLERK 7902 17/12/1980 800 20
7499 ALLEN SALESMAN 7698 20/02/1981 1600 300 30
7521 WARD SALESMAN 7698 22/02/1981 1250 500 30
7566 JONES MANAGER 7839 02/04/1981 2975 20
7698 BLAKE MANAGER 7839 01/05/1981 2850 30
7782 CLARK MANAGER 7839 09/06/1981 2450 10
7844 TURNER SALESMAN 7698 08/09/1981 1500 0 30
7654 MARTIN SALESMAN 7698 28/09/1981 1250 1400 30
7839 KING PRESIDENT 17/11/1981 5000 10
7900 JAMES CLERK 7698 03/12/1981 950 30
7902 FORD ANALYST 7566 03/12/1981 3000 20
7934 MILLER CLERK 7782 23/01/1982 1300 10
7788 SCOTT ANALYST 7566 19/04/1987 3000 20
7876 ADAMS CLERK 7788 23/05/1987 1100 20
SELECT *
FROM EMP
MATCH_RECOGNIZE (
ORDER BY HIREDATE
ALL ROWS PER MATCH
PATTERN (D30 D30)
DEFINE D30 AS DEPTNO=30
)
D30
Find 2 employees hired successively to department 30






Pattern
Variableorder by
1
2
This presentation is available in http://db-oriented.com/presentations
©OrenNakdimon©OrenNakdimon
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
7369 SMITH CLERK 7902 17/12/1980 800 20
7499 ALLEN SALESMAN 7698 20/02/1981 1600 300 30
7521 WARD SALESMAN 7698 22/02/1981 1250 500 30
7566 JONES MANAGER 7839 02/04/1981 2975 20
7698 BLAKE MANAGER 7839 01/05/1981 2850 30
7782 CLARK MANAGER 7839 09/06/1981 2450 10
7844 TURNER SALESMAN 7698 08/09/1981 1500 0 30
7654 MARTIN SALESMAN 7698 28/09/1981 1250 1400 30
7839 KING PRESIDENT 17/11/1981 5000 10
7900 JAMES CLERK 7698 03/12/1981 950 30
7902 FORD ANALYST 7566 03/12/1981 3000 20
7934 MILLER CLERK 7782 23/01/1982 1300 10
7788 SCOTT ANALYST 7566 19/04/1987 3000 20
7876 ADAMS CLERK 7788 23/05/1987 1100 20
SELECT *
FROM EMP
MATCH_RECOGNIZE (
ORDER BY HIREDATE
ALL ROWS PER MATCH
PATTERN (D30{2})
DEFINE D30 AS DEPTNO=30
)
D30
Find 2 employees hired successively to department 30






Pattern
Variableorder by
1
2
This presentation is available in http://db-oriented.com/presentations
©OrenNakdimon©OrenNakdimon
PATTERN Quantifiers
Pattern Number of consecutive occurrences
X 1
X{n} n
X+ 1 or more
X{n,} n or more
X{n,m} between n and m
X{,m} between 0 and m
X* 0 or more
X? 0 or 1
This presentation is available in http://db-oriented.com/presentations
©OrenNakdimon©OrenNakdimon
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
7369 SMITH CLERK 7902 17/12/1980 800 20
7499 ALLEN SALESMAN 7698 20/02/1981 1600 300 30
7521 WARD SALESMAN 7698 22/02/1981 1250 500 30
7566 JONES MANAGER 7839 02/04/1981 2975 20
7698 BLAKE MANAGER 7839 01/05/1981 2850 30
7782 CLARK MANAGER 7839 09/06/1981 2450 10
7844 TURNER SALESMAN 7698 08/09/1981 1500 0 30
7654 MARTIN SALESMAN 7698 28/09/1981 1250 1400 30
7839 KING PRESIDENT 17/11/1981 5000 10
7900 JAMES CLERK 7698 03/12/1981 950 30
7902 FORD ANALYST 7566 03/12/1981 3000 20
7934 MILLER CLERK 7782 23/01/1982 1300 10
7788 SCOTT ANALYST 7566 19/04/1987 3000 20
7876 ADAMS CLERK 7788 23/05/1987 1100 20
SELECT *
FROM EMP
MATCH_RECOGNIZE (
ORDER BY HIREDATE
ALL ROWS PER MATCH
PATTERN (D30+)
DEFINE D30 AS DEPTNO=30
)
D30
Find one or more employees hired successively to department 30






Pattern
Variableorder by
1
2
3
4
This presentation is available in http://db-oriented.com/presentations
©OrenNakdimon©OrenNakdimon
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
7369 SMITH CLERK 7902 17/12/1980 800 20
7499 ALLEN SALESMAN 7698 20/02/1981 1600 300 30
7521 WARD SALESMAN 7698 22/02/1981 1250 500 30
7566 JONES MANAGER 7839 02/04/1981 2975 20
7698 BLAKE MANAGER 7839 01/05/1981 2850 30
7782 CLARK MANAGER 7839 09/06/1981 2450 10
7844 TURNER SALESMAN 7698 08/09/1981 1500 0 30
7654 MARTIN SALESMAN 7698 28/09/1981 1250 1400 30
7839 KING PRESIDENT 17/11/1981 5000 10
7900 JAMES CLERK 7698 03/12/1981 950 30
7902 FORD ANALYST 7566 03/12/1981 3000 20
7934 MILLER CLERK 7782 23/01/1982 1300 10
7788 SCOTT ANALYST 7566 19/04/1987 3000 20
7876 ADAMS CLERK 7788 23/05/1987 1100 20
D30
Multiple Pattern Variables






Pattern
Variables
D20 LS












SELECT *
FROM EMP
MATCH_RECOGNIZE (
ORDER BY HIREDATE
ALL ROWS PER MATCH
PATTERN (D30 D20 LS?)
DEFINE D30 AS DEPTNO=30,
D20 AS DEPTNO=20,
LS AS SAL<=1500
)
order by
This presentation is available in http://db-oriented.com/presentations
©OrenNakdimon©OrenNakdimon
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
7369 SMITH CLERK 7902 17/12/1980 800 20
7499 ALLEN SALESMAN 7698 20/02/1981 1600 300 30
7521 WARD SALESMAN 7698 22/02/1981 1250 500 30
7566 JONES MANAGER 7839 02/04/1981 2975 20
7698 BLAKE MANAGER 7839 01/05/1981 2850 30
7782 CLARK MANAGER 7839 09/06/1981 2450 10
7844 TURNER SALESMAN 7698 08/09/1981 1500 0 30
7654 MARTIN SALESMAN 7698 28/09/1981 1250 1400 30
7839 KING PRESIDENT 17/11/1981 5000 10
7900 JAMES CLERK 7698 03/12/1981 950 30
7902 FORD ANALYST 7566 03/12/1981 3000 20
7934 MILLER CLERK 7782 23/01/1982 1300 10
7788 SCOTT ANALYST 7566 19/04/1987 3000 20
7876 ADAMS CLERK 7788 23/05/1987 1100 20
D30
Multiple Pattern Variables


Pattern
Variables
D20 LS



SELECT *
FROM EMP
MATCH_RECOGNIZE (
ORDER BY HIREDATE
ALL ROWS PER MATCH
PATTERN (D30 D20 LS?)
DEFINE D30 AS DEPTNO=30,
D20 AS DEPTNO=20,
LS AS SAL<=1500
)
order by
This presentation is available in http://db-oriented.com/presentations
©OrenNakdimon©OrenNakdimon
Dividing the Input Row Set
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
7782 CLARK MANAGER 7839 09/06/1981 2450 10
7839 KING PRESIDENT 17/11/1981 5000 10
7934 MILLER CLERK 7782 23/01/1982 1300 10
7369 SMITH CLERK 7902 17/12/1980 800 20
7566 JONES MANAGER 7839 02/04/1981 2975 20
7902 FORD ANALYST 7566 03/12/1981 3000 20
7788 SCOTT ANALYST 7566 19/04/1987 3000 20
7876 ADAMS CLERK 7788 23/05/1987 1100 20
7499 ALLEN SALESMAN 7698 20/02/1981 1600 300 30
7521 WARD SALESMAN 7698 22/02/1981 1250 500 30
7698 BLAKE MANAGER 7839 01/05/1981 2850 30
7844 TURNER SALESMAN 7698 08/09/1981 1500 0 30
7654 MARTIN SALESMAN 7698 28/09/1981 1250 1400 30
7900 JAMES CLERK 7698 03/12/1981 950 30
HS


LS












order by partition by
Pattern
Variables
SELECT *
FROM EMP
MATCH_RECOGNIZE (
PARTITION BY DEPTNO
ORDER BY HIREDATE
ALL ROWS PER MATCH
PATTERN (HS+ LS*)
DEFINE LS AS SAL<=1500,
HS AS SAL> 1500
)
This presentation is available in http://db-oriented.com/presentations
©OrenNakdimon©OrenNakdimon
Dividing the Input Row Set
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
7782 CLARK MANAGER 7839 09/06/1981 2450 10
7839 KING PRESIDENT 17/11/1981 5000 10
7934 MILLER CLERK 7782 23/01/1982 1300 10
7369 SMITH CLERK 7902 17/12/1980 800 20
7566 JONES MANAGER 7839 02/04/1981 2975 20
7902 FORD ANALYST 7566 03/12/1981 3000 20
7788 SCOTT ANALYST 7566 19/04/1987 3000 20
7876 ADAMS CLERK 7788 23/05/1987 1100 20
7499 ALLEN SALESMAN 7698 20/02/1981 1600 300 30
7521 WARD SALESMAN 7698 22/02/1981 1250 500 30
7698 BLAKE MANAGER 7839 01/05/1981 2850 30
7844 TURNER SALESMAN 7698 08/09/1981 1500 0 30
7654 MARTIN SALESMAN 7698 28/09/1981 1250 1400 30
7900 JAMES CLERK 7698 03/12/1981 950 30
HS


LS












order by partition by
Pattern
Variables
SELECT *
FROM EMP
MATCH_RECOGNIZE (
PARTITION BY DEPTNO
ORDER BY HIREDATE
ALL ROWS PER MATCH
PATTERN (HS+ LS*)
DEFINE LS AS SAL<=1500,
HS AS SAL> 1500
)
This presentation is available in http://db-oriented.com/presentations
©OrenNakdimon©OrenNakdimon
Adding Measures
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
7782 CLARK MANAGER 7839 09/06/1981 2450 10
7839 KING PRESIDENT 17/11/1981 5000 10
7934 MILLER CLERK 7782 23/01/1982 1300 10
7369 SMITH CLERK 7902 17/12/1980 800 20
7566 JONES MANAGER 7839 02/04/1981 2975 20
7902 FORD ANALYST 7566 03/12/1981 3000 20
7788 SCOTT ANALYST 7566 19/04/1987 3000 20
7876 ADAMS CLERK 7788 23/05/1987 1100 20
7499 ALLEN SALESMAN 7698 20/02/1981 1600 300 30
7521 WARD SALESMAN 7698 22/02/1981 1250 500 30
7698 BLAKE MANAGER 7839 01/05/1981 2850 30
7844 TURNER SALESMAN 7698 08/09/1981 1500 0 30
7654 MARTIN SALESMAN 7698 28/09/1981 1250 1400 30
7900 JAMES CLERK 7698 03/12/1981 950 30
HS


LS












order by partition by
Pattern
Variables
SELECT *
FROM EMP
MATCH_RECOGNIZE (
PARTITION BY DEPTNO
ORDER BY HIREDATE
MEASURES
MATCH_NUMBER() as MATCH#
ALL ROWS PER MATCH
PATTERN (HS+ LS*)
DEFINE LS AS SAL<=1500,
HS AS SAL> 1500
)
This presentation is available in http://db-oriented.com/presentations
©OrenNakdimon©OrenNakdimon
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
7782 CLARK MANAGER 7839 09/06/1981 2450 10
7839 KING PRESIDENT 17/11/1981 5000 10
7934 MILLER CLERK 7782 23/01/1982 1300 10
7369 SMITH CLERK 7902 17/12/1980 800 20
7566 JONES MANAGER 7839 02/04/1981 2975 20
7902 FORD ANALYST 7566 03/12/1981 3000 20
7788 SCOTT ANALYST 7566 19/04/1987 3000 20
7876 ADAMS CLERK 7788 23/05/1987 1100 20
7499 ALLEN SALESMAN 7698 20/02/1981 1600 300 30
7521 WARD SALESMAN 7698 22/02/1981 1250 500 30
7698 BLAKE MANAGER 7839 01/05/1981 2850 30
7844 TURNER SALESMAN 7698 08/09/1981 1500 0 30
7654 MARTIN SALESMAN 7698 28/09/1981 1250 1400 30
7900 JAMES CLERK 7698 03/12/1981 950 30
Adding Measures
HS


LS












order by partition by
Pattern
Variables
SELECT *
FROM EMP
MATCH_RECOGNIZE (
PARTITION BY DEPTNO
ORDER BY HIREDATE
MEASURES
MATCH_NUMBER() as MATCH#
ALL ROWS PER MATCH
AFTER MATCH SKIP PAST LAST ROW
PATTERN (HS+ LS*)
DEFINE LS AS SAL<=1500,
HS AS SAL> 1500
)
This presentation is available in http://db-oriented.com/presentations
©OrenNakdimon©OrenNakdimon
AFTER MATCH SKIP
 PAST LAST ROW (the default)
 TO NEXT ROW
 TO FIRST var
 TO [LAST] var
This presentation is available in http://db-oriented.com/presentations
©OrenNakdimon©OrenNakdimon
Adding Measures
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
7782 CLARK MANAGER 7839 09/06/1981 2450 10
7839 KING PRESIDENT 17/11/1981 5000 10
7934 MILLER CLERK 7782 23/01/1982 1300 10
7369 SMITH CLERK 7902 17/12/1980 800 20
7566 JONES MANAGER 7839 02/04/1981 2975 20
7902 FORD ANALYST 7566 03/12/1981 3000 20
7788 SCOTT ANALYST 7566 19/04/1987 3000 20
7876 ADAMS CLERK 7788 23/05/1987 1100 20
7499 ALLEN SALESMAN 7698 20/02/1981 1600 300 30
7521 WARD SALESMAN 7698 22/02/1981 1250 500 30
7698 BLAKE MANAGER 7839 01/05/1981 2850 30
7844 TURNER SALESMAN 7698 08/09/1981 1500 0 30
7654 MARTIN SALESMAN 7698 28/09/1981 1250 1400 30
7900 JAMES CLERK 7698 03/12/1981 950 30
HS


LS












order by partition by
Pattern
Variables
SELECT *
FROM EMP
MATCH_RECOGNIZE (
PARTITION BY DEPTNO
ORDER BY HIREDATE
MEASURES
MATCH_NUMBER() as MATCH#
ALL ROWS PER MATCH
PATTERN (HS+ LS*)
DEFINE LS AS SAL<=1500,
HS AS SAL> 1500
)
SELECT *
FROM EMP
MATCH_RECOGNIZE (
PARTITION BY DEPTNO
ORDER BY HIREDATE
MEASURES
MATCH_NUMBER() as MATCH#
ALL ROWS PER MATCH
AFTER MATCH SKIP TO NEXT ROW
PATTERN (HS+ LS*)
DEFINE LS AS SAL<=1500,
HS AS SAL> 1500
)
This presentation is available in http://db-oriented.com/presentations
©OrenNakdimon©OrenNakdimon
Adding Measures
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
7782 CLARK MANAGER 7839 09/06/1981 2450 10
7839 KING PRESIDENT 17/11/1981 5000 10
7934 MILLER CLERK 7782 23/01/1982 1300 10
7369 SMITH CLERK 7902 17/12/1980 800 20
7566 JONES MANAGER 7839 02/04/1981 2975 20
7902 FORD ANALYST 7566 03/12/1981 3000 20
7788 SCOTT ANALYST 7566 19/04/1987 3000 20
7876 ADAMS CLERK 7788 23/05/1987 1100 20
7499 ALLEN SALESMAN 7698 20/02/1981 1600 300 30
7521 WARD SALESMAN 7698 22/02/1981 1250 500 30
7698 BLAKE MANAGER 7839 01/05/1981 2850 30
7844 TURNER SALESMAN 7698 08/09/1981 1500 0 30
7654 MARTIN SALESMAN 7698 28/09/1981 1250 1400 30
7900 JAMES CLERK 7698 03/12/1981 950 30
HS


LS












order by partition by
Pattern
Variables
SELECT *
FROM EMP
MATCH_RECOGNIZE (
PARTITION BY DEPTNO
ORDER BY HIREDATE
MEASURES
MATCH_NUMBER() as MATCH#
ALL ROWS PER MATCH
PATTERN (HS+ LS*)
DEFINE LS AS SAL<=1500,
HS AS SAL> 1500
)
SELECT *
FROM EMP
MATCH_RECOGNIZE (
PARTITION BY DEPTNO
ORDER BY HIREDATE
MEASURES
MATCH_NUMBER() as MATCH#
ALL ROWS PER MATCH
AFTER MATCH SKIP TO NEXT ROW
PATTERN (HS+ LS*)
DEFINE LS AS SAL<=1500,
HS AS SAL> 1500
)
This presentation is available in http://db-oriented.com/presentations
©OrenNakdimon©OrenNakdimon
Uniting Adjacent Periods
KNESSET_
NUMBER PRIME_MINISTER START_DATE END_DATE
0 ‫בן‬ ‫דוד‬-‫גוריון‬ 14/05/1948 10/03/1949
1 ‫בן‬ ‫דוד‬-‫גוריון‬ 10/03/1949 01/11/1950
1 ‫בן‬ ‫דוד‬-‫גוריון‬ 01/11/1950 08/10/1951
2 ‫בן‬ ‫דוד‬-‫גוריון‬ 08/10/1951 24/12/1952
2 ‫בן‬ ‫דוד‬-‫גוריון‬ 24/12/1952 26/01/1954
2 ‫שרת‬ ‫משה‬ 26/01/1954 29/06/1955
2 ‫שרת‬ ‫משה‬ 29/06/1955 03/11/1955
3 ‫בן‬ ‫דוד‬-‫גוריון‬ 03/11/1955 07/01/1958
3 ‫בן‬ ‫דוד‬-‫גוריון‬ 07/01/1958 17/12/1959
4 ‫בן‬ ‫דוד‬-‫גוריון‬ 17/12/1959 02/11/1961
5 ‫בן‬ ‫דוד‬-‫גוריון‬ 02/11/1961 26/06/1963
5 ‫אשכול‬ ‫לוי‬ 26/06/1963 22/12/1964
5 ‫אשכול‬ ‫לוי‬ 22/12/1964 12/01/1966
6 ‫אשכול‬ ‫לוי‬ 12/01/1966 26/02/1969
6 ‫מאיר‬ ‫גולדה‬ 17/03/1969 15/12/1969
7 ‫מאיר‬ ‫גולדה‬ 15/12/1969 10/03/1974
8 ‫מאיר‬ ‫גולדה‬ 10/03/1974 03/06/1974
8 ‫רבין‬ ‫יצחק‬ 03/06/1974 20/06/1977
9 ‫בגין‬ ‫מנחם‬ 20/06/1977 05/08/1981
10 ‫בגין‬ ‫מנחם‬ 05/08/1981 10/10/1983
10 ‫שמיר‬ ‫יצחק‬ 10/10/1983 13/09/1984
11 ‫פרס‬ ‫שמעון‬ 13/09/1984 20/10/1986
11 ‫שמיר‬ ‫יצחק‬ 20/10/1986 22/12/1988
12 ‫שמיר‬ ‫יצחק‬ 22/12/1988 11/06/1990
12 ‫שמיר‬ ‫יצחק‬ 11/06/1990 13/07/1992
13 ‫רבין‬ ‫יצחק‬ 13/07/1992 04/11/1995
13 ‫פרס‬ ‫שמעון‬ 22/11/1995 18/06/1996
14 ‫נתניהו‬ ‫בנימין‬ 18/06/1996 06/07/1999
15 ‫ברק‬ ‫אהוד‬ 06/07/1999 07/03/2001
15 ‫שרון‬ ‫אריאל‬ 07/03/2001 28/02/2003
16 ‫שרון‬ ‫אריאל‬ 28/02/2003 16/04/2006
17 ‫אולמרט‬ ‫אהוד‬ 04/05/2006 31/03/2009
18 ‫נתניהו‬ ‫בנימין‬ 31/03/2009 18/03/2013
19 ‫נתניהו‬ ‫בנימין‬ 18/03/2013 14/05/2015
20 ‫נתניהו‬ ‫בנימין‬ 14/05/2015
This presentation is available in http://db-oriented.com/presentations
©OrenNakdimon©OrenNakdimon
Uniting Adjacent Periods
KNESSET_
NUMBER PRIME_MINISTER START_DATE END_DATE
0 ‫בן‬ ‫דוד‬-‫גוריון‬ 14/05/1948 10/03/1949
1 ‫בן‬ ‫דוד‬-‫גוריון‬ 10/03/1949 01/11/1950
1 ‫בן‬ ‫דוד‬-‫גוריון‬ 01/11/1950 08/10/1951
2 ‫בן‬ ‫דוד‬-‫גוריון‬ 08/10/1951 24/12/1952
2 ‫בן‬ ‫דוד‬-‫גוריון‬ 24/12/1952 26/01/1954
2 ‫שרת‬ ‫משה‬ 26/01/1954 29/06/1955
2 ‫שרת‬ ‫משה‬ 29/06/1955 03/11/1955
3 ‫בן‬ ‫דוד‬-‫גוריון‬ 03/11/1955 07/01/1958
3 ‫בן‬ ‫דוד‬-‫גוריון‬ 07/01/1958 17/12/1959
4 ‫בן‬ ‫דוד‬-‫גוריון‬ 17/12/1959 02/11/1961
5 ‫בן‬ ‫דוד‬-‫גוריון‬ 02/11/1961 26/06/1963
5 ‫אשכול‬ ‫לוי‬ 26/06/1963 22/12/1964
5 ‫אשכול‬ ‫לוי‬ 22/12/1964 12/01/1966
6 ‫אשכול‬ ‫לוי‬ 12/01/1966 26/02/1969
6 ‫מאיר‬ ‫גולדה‬ 17/03/1969 15/12/1969
7 ‫מאיר‬ ‫גולדה‬ 15/12/1969 10/03/1974
8 ‫מאיר‬ ‫גולדה‬ 10/03/1974 03/06/1974
8 ‫רבין‬ ‫יצחק‬ 03/06/1974 20/06/1977
9 ‫בגין‬ ‫מנחם‬ 20/06/1977 05/08/1981
10 ‫בגין‬ ‫מנחם‬ 05/08/1981 10/10/1983
10 ‫שמיר‬ ‫יצחק‬ 10/10/1983 13/09/1984
11 ‫פרס‬ ‫שמעון‬ 13/09/1984 20/10/1986
11 ‫שמיר‬ ‫יצחק‬ 20/10/1986 22/12/1988
12 ‫שמיר‬ ‫יצחק‬ 22/12/1988 11/06/1990
12 ‫שמיר‬ ‫יצחק‬ 11/06/1990 13/07/1992
13 ‫רבין‬ ‫יצחק‬ 13/07/1992 04/11/1995
13 ‫פרס‬ ‫שמעון‬ 22/11/1995 18/06/1996
14 ‫נתניהו‬ ‫בנימין‬ 18/06/1996 06/07/1999
15 ‫ברק‬ ‫אהוד‬ 06/07/1999 07/03/2001
15 ‫שרון‬ ‫אריאל‬ 07/03/2001 28/02/2003
16 ‫שרון‬ ‫אריאל‬ 28/02/2003 16/04/2006
17 ‫אולמרט‬ ‫אהוד‬ 04/05/2006 31/03/2009
18 ‫נתניהו‬ ‫בנימין‬ 31/03/2009 18/03/2013
19 ‫נתניהו‬ ‫בנימין‬ 18/03/2013 14/05/2015
20 ‫נתניהו‬ ‫בנימין‬ 14/05/2015
This presentation is available in http://db-oriented.com/presentations
©OrenNakdimon©OrenNakdimon
KNESSET_
NUMBER PRIME_MINISTER START_DATE END_DATE
17 ‫אולמרט‬ ‫אהוד‬ 04/05/2006 31/03/2009
15 ‫ברק‬ ‫אהוד‬ 06/07/1999 07/03/2001
15 ‫שרון‬ ‫אריאל‬ 07/03/2001 28/02/2003
16 ‫שרון‬ ‫אריאל‬ 28/02/2003 16/04/2006
14 ‫נתניהו‬ ‫בנימין‬ 18/06/1996 06/07/1999
18 ‫נתניהו‬ ‫בנימין‬ 31/03/2009 18/03/2013
19 ‫נתניהו‬ ‫בנימין‬ 18/03/2013 14/05/2015
20 ‫נתניהו‬ ‫בנימין‬ 14/05/2015
6 ‫מאיר‬ ‫גולדה‬ 17/03/1969 15/12/1969
7 ‫מאיר‬ ‫גולדה‬ 15/12/1969 10/03/1974
8 ‫מאיר‬ ‫גולדה‬ 10/03/1974 03/06/1974
0 ‫בן‬ ‫דוד‬-‫גוריון‬ 14/05/1948 10/03/1949
1 ‫בן‬ ‫דוד‬-‫גוריון‬ 10/03/1949 01/11/1950
1 ‫בן‬ ‫דוד‬-‫גוריון‬ 01/11/1950 08/10/1951
2 ‫בן‬ ‫דוד‬-‫גוריון‬ 08/10/1951 24/12/1952
2 ‫בן‬ ‫דוד‬-‫גוריון‬ 24/12/1952 26/01/1954
3 ‫בן‬ ‫דוד‬-‫גוריון‬ 03/11/1955 07/01/1958
3 ‫בן‬ ‫דוד‬-‫גוריון‬ 07/01/1958 17/12/1959
4 ‫בן‬ ‫דוד‬-‫גוריון‬ 17/12/1959 02/11/1961
5 ‫בן‬ ‫דוד‬-‫גוריון‬ 02/11/1961 26/06/1963
8 ‫רבין‬ ‫יצחק‬ 03/06/1974 20/06/1977
13 ‫רבין‬ ‫יצחק‬ 13/07/1992 04/11/1995
partition by
NXT












order by
This presentation is available in http://db-oriented.com/presentations
©OrenNakdimon©OrenNakdimon
SELECT *
FROM ISRAEL_CABINETS
MATCH_RECOGNIZE (
PARTITION BY PRIME_MINISTER
ORDER BY START_DATE, END_DATE
MEASURES
MATCH_NUMBER() CONT_PERIOD#
ALL ROWS PER MATCH
PATTERN (STRT NXT*)
DEFINE NXT AS START_DATE = PREV(END_DATE)
)
ORDER BY START_DATE;
And if we want at
least two tenures?
This presentation is available in http://db-oriented.com/presentations
©OrenNakdimon©OrenNakdimon
SELECT *
FROM ISRAEL_CABINETS
MATCH_RECOGNIZE (
PARTITION BY PRIME_MINISTER
ORDER BY START_DATE, END_DATE
MEASURES
MATCH_NUMBER() CONT_PERIOD#
ALL ROWS PER MATCH
PATTERN (STRT NXT+)
DEFINE NXT AS START_DATE = PREV(END_DATE)
)
ORDER BY START_DATE;
This presentation is available in http://db-oriented.com/presentations
©OrenNakdimon©OrenNakdimon
SELECT *
FROM ISRAEL_CABINETS
MATCH_RECOGNIZE (
PARTITION BY PRIME_MINISTER
ORDER BY START_DATE, END_DATE
MEASURES
MATCH_NUMBER() CONT_PERIOD#,
CLASSIFIER() CLS
ALL ROWS PER MATCH
PATTERN (STRT NXT*)
DEFINE NXT AS START_DATE = PREV(END_DATE)
)
ORDER BY START_DATE;
This presentation is available in http://db-oriented.com/presentations
©OrenNakdimon©OrenNakdimon
SELECT *
FROM ISRAEL_CABINETS
MATCH_RECOGNIZE (
PARTITION BY PRIME_MINISTER
ORDER BY START_DATE, END_DATE
MEASURES
MATCH_NUMBER() CONT_PERIOD#,
CLASSIFIER() CLS,
END_DATE - START_DATE days_in_this_period
ALL ROWS PER MATCH
PATTERN (STRT NXT*)
DEFINE NXT AS START_DATE = PREV(END_DATE)
)
ORDER BY START_DATE;
This presentation is available in http://db-oriented.com/presentations
©OrenNakdimon©OrenNakdimon
SELECT *
FROM ISRAEL_CABINETS
MATCH_RECOGNIZE (
PARTITION BY PRIME_MINISTER
ORDER BY START_DATE, END_DATE
MEASURES
MATCH_NUMBER() CONT_PERIOD#,
CLASSIFIER() CLS,
END_DATE - START_DATE days_in_this_period,
END_DATE - STRT.START_DATE days_since_cont_period_start
ALL ROWS PER MATCH
PATTERN (STRT NXT*)
DEFINE NXT AS START_DATE = PREV(END_DATE)
)
ORDER BY START_DATE;
This presentation is available in http://db-oriented.com/presentations
©OrenNakdimon©OrenNakdimon
SELECT *
FROM ISRAEL_CABINETS
MATCH_RECOGNIZE (
PARTITION BY PRIME_MINISTER
ORDER BY START_DATE, END_DATE
MEASURES
MATCH_NUMBER() CONT_PERIOD#,
CLASSIFIER() CLS,
END_DATE - START_DATE days_in_this_period,
END_DATE - STRT.START_DATE days_since_cont_period_start,
LAST(END_DATE) - FIRST(START_DATE) total_days
ALL ROWS PER MATCH
PATTERN (STRT NXT*)
DEFINE NXT AS START_DATE = PREV(END_DATE)
)
ORDER BY START_DATE;
This presentation is available in http://db-oriented.com/presentations
©OrenNakdimon©OrenNakdimon
SELECT *
FROM ISRAEL_CABINETS
MATCH_RECOGNIZE (
PARTITION BY PRIME_MINISTER
ORDER BY START_DATE, END_DATE
MEASURES
MATCH_NUMBER() CONT_PERIOD#,
CLASSIFIER() CLS,
END_DATE - START_DATE days_in_this_period,
END_DATE - STRT.START_DATE days_since_cont_period_start,
RUNNING LAST(END_DATE) - FIRST(START_DATE) total_days
ALL ROWS PER MATCH
PATTERN (STRT NXT*)
DEFINE NXT AS START_DATE = PREV(END_DATE)
)
ORDER BY START_DATE;
This presentation is available in http://db-oriented.com/presentations
©OrenNakdimon©OrenNakdimon
SELECT *
FROM ISRAEL_CABINETS
MATCH_RECOGNIZE (
PARTITION BY PRIME_MINISTER
ORDER BY START_DATE, END_DATE
MEASURES
MATCH_NUMBER() CONT_PERIOD#,
CLASSIFIER() CLS,
END_DATE - START_DATE days_in_this_period,
END_DATE - STRT.START_DATE days_since_cont_period_start,
FINAL LAST(END_DATE) - FIRST(START_DATE) total_days
ALL ROWS PER MATCH
PATTERN (STRT NXT*)
DEFINE NXT AS START_DATE = PREV(END_DATE)
)
ORDER BY START_DATE;
This presentation is available in http://db-oriented.com/presentations
©OrenNakdimon©OrenNakdimon
SELECT *
FROM ISRAEL_CABINETS
MATCH_RECOGNIZE (
PARTITION BY PRIME_MINISTER
ORDER BY START_DATE
MEASURES MATCH_NUMBER() cont_period#,
FIRST(START_DATE) cont_period_start,
LAST(END_DATE) cont_period_end,
COUNT(*) num_of_periods
ONE ROW PER MATCH
PATTERN (STRT NXT*)
DEFINE NXT AS START_DATE = PREV(END_DATE)
)
ORDER BY CONT_PERIOD_START;
COUNT
MAX
MIN
SUM
AVG
This presentation is available in http://db-oriented.com/presentations
©OrenNakdimon©OrenNakdimon
Find returning prime ministers after a break
KNESSET_
NUMBER PRIME_MINISTER START_DATE END_DATE
0 ‫בן‬ ‫דוד‬-‫גוריון‬ 14/05/1948 10/03/1949
1 ‫בן‬ ‫דוד‬-‫גוריון‬ 10/03/1949 01/11/1950
1 ‫בן‬ ‫דוד‬-‫גוריון‬ 01/11/1950 08/10/1951
2 ‫בן‬ ‫דוד‬-‫גוריון‬ 08/10/1951 24/12/1952
2 ‫בן‬ ‫דוד‬-‫גוריון‬ 24/12/1952 26/01/1954
2 ‫שרת‬ ‫משה‬ 26/01/1954 29/06/1955
2 ‫שרת‬ ‫משה‬ 29/06/1955 03/11/1955
3 ‫בן‬ ‫דוד‬-‫גוריון‬ 03/11/1955 07/01/1958
3 ‫בן‬ ‫דוד‬-‫גוריון‬ 07/01/1958 17/12/1959
4 ‫בן‬ ‫דוד‬-‫גוריון‬ 17/12/1959 02/11/1961
5 ‫בן‬ ‫דוד‬-‫גוריון‬ 02/11/1961 26/06/1963
5 ‫אשכול‬ ‫לוי‬ 26/06/1963 22/12/1964
5 ‫אשכול‬ ‫לוי‬ 22/12/1964 12/01/1966
6 ‫אשכול‬ ‫לוי‬ 12/01/1966 26/02/1969
6 ‫מאיר‬ ‫גולדה‬ 17/03/1969 15/12/1969
7 ‫מאיר‬ ‫גולדה‬ 15/12/1969 10/03/1974
8 ‫מאיר‬ ‫גולדה‬ 10/03/1974 03/06/1974
8 ‫רבין‬ ‫יצחק‬ 03/06/1974 20/06/1977
9 ‫בגין‬ ‫מנחם‬ 20/06/1977 05/08/1981
10 ‫בגין‬ ‫מנחם‬ 05/08/1981 10/10/1983
10 ‫שמיר‬ ‫יצחק‬ 10/10/1983 13/09/1984
11 ‫פרס‬ ‫שמעון‬ 13/09/1984 20/10/1986
11 ‫שמיר‬ ‫יצחק‬ 20/10/1986 22/12/1988
12 ‫שמיר‬ ‫יצחק‬ 22/12/1988 11/06/1990
12 ‫שמיר‬ ‫יצחק‬ 11/06/1990 13/07/1992
13 ‫רבין‬ ‫יצחק‬ 13/07/1992 04/11/1995
13 ‫פרס‬ ‫שמעון‬ 22/11/1995 18/06/1996
14 ‫נתניהו‬ ‫בנימין‬ 18/06/1996 06/07/1999
15 ‫ברק‬ ‫אהוד‬ 06/07/1999 07/03/2001
15 ‫שרון‬ ‫אריאל‬ 07/03/2001 28/02/2003
16 ‫שרון‬ ‫אריאל‬ 28/02/2003 16/04/2006
17 ‫אולמרט‬ ‫אהוד‬ 04/05/2006 31/03/2009
18 ‫נתניהו‬ ‫בנימין‬ 31/03/2009 18/03/2013
19 ‫נתניהו‬ ‫בנימין‬ 18/03/2013 14/05/2015
20 ‫נתניהו‬ ‫בנימין‬ 14/05/2015
This presentation is available in http://db-oriented.com/presentations
©OrenNakdimon©OrenNakdimon
Find returning prime ministers after a break
SELECT *
FROM ISRAEL_CABINETS
MATCH_RECOGNIZE (
ORDER BY START_DATE, END_DATE
ALL ROWS PER MATCH
PATTERN (
)
This presentation is available in http://db-oriented.com/presentations
©OrenNakdimon©OrenNakdimon
Find returning prime ministers after a break
SELECT *
FROM ISRAEL_CABINETS
MATCH_RECOGNIZE (
ORDER BY START_DATE, END_DATE
ALL ROWS PER MATCH
PATTERN (A
)
This presentation is available in http://db-oriented.com/presentations
©OrenNakdimon©OrenNakdimon
Find returning prime ministers after a break
SELECT *
FROM ISRAEL_CABINETS
MATCH_RECOGNIZE (
ORDER BY START_DATE, END_DATE
ALL ROWS PER MATCH
PATTERN (A SAME*
)
This presentation is available in http://db-oriented.com/presentations
©OrenNakdimon©OrenNakdimon
Find returning prime ministers after a break
SELECT *
FROM ISRAEL_CABINETS
MATCH_RECOGNIZE (
ORDER BY START_DATE, END_DATE
ALL ROWS PER MATCH
PATTERN (A SAME* DIFF+
)
This presentation is available in http://db-oriented.com/presentations
©OrenNakdimon©OrenNakdimon
Find returning prime ministers after a break
SELECT *
FROM ISRAEL_CABINETS
MATCH_RECOGNIZE (
ORDER BY START_DATE, END_DATE
MEASURES
MATCH_NUMBER() match#,
CLASSIFIER() cls,
COUNT(*) period#,
COUNT(DIFF.*) diff_periods_until_now,
FINAL COUNT(DIFF.*) total_diff_periods,
END_DATE - START_DATE days
ALL ROWS PER MATCH
PATTERN (A SAME* DIFF+ LIKE_FIRST+)
DEFINE
SAME as SAME.PRIME_MINISTER = PREV(SAME.PRIME_MINISTER),
DIFF as LAST(PRIME_MINISTER) != A.PRIME_MINISTER,
LIKE_FIRST as PRIME_MINISTER = A.PRIME_MINISTER
)
ORDER BY MATCH#,START_DATE;
This presentation is available in http://db-oriented.com/presentations
©OrenNakdimon©OrenNakdimon
COUNT(*) COUNT(DIFF.*) FINAL COUNT(DIFF.*)
This presentation is available in http://db-oriented.com/presentations
©OrenNakdimon©OrenNakdimon
Find returning prime ministers after a break
SELECT *
FROM ISRAEL_CABINETS
MATCH_RECOGNIZE (
ORDER BY START_DATE, END_DATE
MEASURES
MATCH_NUMBER() match#,
CLASSIFIER() cls,
COUNT(*) period#,
COUNT(DIFF.*) diff_periods_until_now,
FINAL COUNT(DIFF.*) total_diff_periods,
END_DATE - START_DATE days
ALL ROWS PER MATCH
AFTER MATCH SKIP TO FIRST DIFF
PATTERN (A SAME* DIFF+ LIKE_FIRST+)
DEFINE
SAME as SAME.PRIME_MINISTER = PREV(SAME.PRIME_MINISTER),
DIFF as LAST(PRIME_MINISTER) != A.PRIME_MINISTER,
LIKE_FIRST as PRIME_MINISTER = A.PRIME_MINISTER
)
ORDER BY MATCH#,START_DATE;
This presentation is available in http://db-oriented.com/presentations
©OrenNakdimon©OrenNakdimon
Find returning prime ministers after a break
This presentation is available in http://db-oriented.com/presentations
©OrenNakdimon©OrenNakdimon
Returning prime ministers after a break of exactly one other PM
SELECT *
FROM ISRAEL_CABINETS
MATCH_RECOGNIZE (
ORDER BY START_DATE, END_DATE
MEASURES
MATCH_NUMBER() match#,
CLASSIFIER() cls,
COUNT(*) period#
ALL ROWS PER MATCH
AFTER MATCH SKIP TO FIRST DIFF
PATTERN (A
DEFINE
SAME as SAME.PRIME_MINISTER = PREV(SAME.PRIME_MINISTER),
DIFF as LAST(PRIME_MINISTER) != A.PRIME_MINISTER,
LIKE_FIRST as PRIME_MINISTER = A.PRIME_MINISTER
)
ORDER BY MATCH#,START_DATE;
This presentation is available in http://db-oriented.com/presentations
©OrenNakdimon©OrenNakdimon
Returning prime ministers after a break of exactly one other PM
SELECT *
FROM ISRAEL_CABINETS
MATCH_RECOGNIZE (
ORDER BY START_DATE, END_DATE
MEASURES
MATCH_NUMBER() match#,
CLASSIFIER() cls,
COUNT(*) period#
ALL ROWS PER MATCH
AFTER MATCH SKIP TO FIRST DIFF
PATTERN (A SAME*
DEFINE
SAME as SAME.PRIME_MINISTER = PREV(SAME.PRIME_MINISTER),
DIFF as LAST(PRIME_MINISTER) != A.PRIME_MINISTER,
LIKE_FIRST as PRIME_MINISTER = A.PRIME_MINISTER
)
ORDER BY MATCH#,START_DATE;
This presentation is available in http://db-oriented.com/presentations
©OrenNakdimon©OrenNakdimon
Returning prime ministers after a break of exactly one other PM
SELECT *
FROM ISRAEL_CABINETS
MATCH_RECOGNIZE (
ORDER BY START_DATE, END_DATE
MEASURES
MATCH_NUMBER() match#,
CLASSIFIER() cls,
COUNT(*) period#
ALL ROWS PER MATCH
AFTER MATCH SKIP TO FIRST DIFF
PATTERN (A SAME* DIFF
DEFINE
SAME as SAME.PRIME_MINISTER = PREV(SAME.PRIME_MINISTER),
DIFF as LAST(PRIME_MINISTER) != A.PRIME_MINISTER,
LIKE_FIRST as PRIME_MINISTER = A.PRIME_MINISTER
)
ORDER BY MATCH#,START_DATE;
This presentation is available in http://db-oriented.com/presentations
©OrenNakdimon©OrenNakdimon
Returning prime ministers after a break of exactly one other PM
SELECT *
FROM ISRAEL_CABINETS
MATCH_RECOGNIZE (
ORDER BY START_DATE, END_DATE
MEASURES
MATCH_NUMBER() match#,
CLASSIFIER() cls,
COUNT(*) period#
ALL ROWS PER MATCH
AFTER MATCH SKIP TO FIRST DIFF
PATTERN (A SAME* DIFF SAME*
DEFINE
SAME as SAME.PRIME_MINISTER = PREV(SAME.PRIME_MINISTER),
DIFF as LAST(PRIME_MINISTER) != A.PRIME_MINISTER,
LIKE_FIRST as PRIME_MINISTER = A.PRIME_MINISTER
)
ORDER BY MATCH#,START_DATE;
This presentation is available in http://db-oriented.com/presentations
©OrenNakdimon©OrenNakdimon
Returning prime ministers after a break of exactly one other PM
SELECT *
FROM ISRAEL_CABINETS
MATCH_RECOGNIZE (
ORDER BY START_DATE, END_DATE
MEASURES
MATCH_NUMBER() match#,
CLASSIFIER() cls,
COUNT(*) period#
ALL ROWS PER MATCH
AFTER MATCH SKIP TO FIRST DIFF
PATTERN (A SAME* DIFF SAME* LIKE_FIRST
DEFINE
SAME as SAME.PRIME_MINISTER = PREV(SAME.PRIME_MINISTER),
DIFF as LAST(PRIME_MINISTER) != A.PRIME_MINISTER,
LIKE_FIRST as PRIME_MINISTER = A.PRIME_MINISTER
)
ORDER BY MATCH#,START_DATE;
This presentation is available in http://db-oriented.com/presentations
©OrenNakdimon©OrenNakdimon
Returning prime ministers after a break of exactly one other PM
SELECT *
FROM ISRAEL_CABINETS
MATCH_RECOGNIZE (
ORDER BY START_DATE, END_DATE
MEASURES
MATCH_NUMBER() match#,
CLASSIFIER() cls,
COUNT(*) period#
ALL ROWS PER MATCH
AFTER MATCH SKIP TO FIRST DIFF
PATTERN (A SAME* DIFF SAME* LIKE_FIRST SAME*)
DEFINE
SAME as SAME.PRIME_MINISTER = PREV(SAME.PRIME_MINISTER),
DIFF as LAST(PRIME_MINISTER) != A.PRIME_MINISTER,
LIKE_FIRST as PRIME_MINISTER = A.PRIME_MINISTER
)
ORDER BY MATCH#,START_DATE;
This presentation is available in http://db-oriented.com/presentations
©OrenNakdimon©OrenNakdimon
Returning prime ministers after a break of exactly one other PM
SELECT *
FROM ISRAEL_CABINETS
MATCH_RECOGNIZE (
ORDER BY START_DATE, END_DATE
MEASURES
MATCH_NUMBER() match#,
CLASSIFIER() cls,
COUNT(*) period#
ALL ROWS PER MATCH
AFTER MATCH SKIP TO FIRST DIFF
PATTERN (A SAME* DIFF SAME* LIKE_FIRST SAME*)
DEFINE
SAME as SAME.PRIME_MINISTER = PREV(SAME.PRIME_MINISTER),
DIFF as LAST(PRIME_MINISTER) != A.PRIME_MINISTER,
LIKE_FIRST as PRIME_MINISTER = A.PRIME_MINISTER
)
ORDER BY MATCH#,START_DATE;
This presentation is available in http://db-oriented.com/presentations
©OrenNakdimon©OrenNakdimon
Fibonacci Numbers
X
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
F







SELECT * FROM
(select rownum X from dual connect by level<=100)
MATCH_RECOGNIZE (
ORDER BY X
MEASURES CLASSIFIER() AS F_OR_NOT
ALL ROWS PER MATCH
PATTERN ((F|NF)+)
DEFINE F AS (X = 1 OR X = 2 OR
X = LAST(F.X,1) + LAST(F.X,2))
); Pattern
Alternation
This presentation is available in http://db-oriented.com/presentations
©OrenNakdimon©OrenNakdimon
Only Fibonacci Numbers
X
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
F







SELECT * FROM
(select rownum X from dual connect by level<=100)
MATCH_RECOGNIZE (
ORDER BY X
MEASURES CLASSIFIER() AS F_OR_NOT
ALL ROWS PER MATCH
PATTERN ((F|{-NF-})+)
DEFINE F AS (X = 1 OR X = 2 OR
X = LAST(F.X,1) + LAST(F.X,2))
); Pattern
Exclusion
This presentation is available in http://db-oriented.com/presentations
©OrenNakdimon©OrenNakdimon
SELECT *
FROM ISRAEL_CABINETS
MATCH_RECOGNIZE (
ORDER BY START_DATE, END_DATE
MEASURES
MATCH_NUMBER() match#,
CLASSIFIER() cls,
END_DATE - START_DATE days
ALL ROWS PER MATCH
AFTER MATCH SKIP TO FIRST DIFF
PATTERN (A SAME* DIFF+ LIKE_FIRST+)
DEFINE
SAME as PRIME_MINISTER = PREV(PRIME_MINISTER),
DIFF as PRIME_MINISTER != A.PRIME_MINISTER,
LIKE_FIRST as PRIME_MINISTER = A.PRIME_MINISTER
)
ORDER BY MATCH#,START_DATE;
This presentation is available in http://db-oriented.com/presentations
©OrenNakdimon©OrenNakdimon
SELECT *
FROM ISRAEL_CABINETS
MATCH_RECOGNIZE (
ORDER BY START_DATE, END_DATE
MEASURES
MATCH_NUMBER() match#,
CLASSIFIER() cls,
END_DATE - START_DATE days,
FINAL AVG(END_DATE - START_DATE) avg_days
ALL ROWS PER MATCH
AFTER MATCH SKIP TO FIRST DIFF
PATTERN (A SAME* DIFF+ LIKE_FIRST+)
DEFINE
SAME as PRIME_MINISTER = PREV(PRIME_MINISTER),
DIFF as PRIME_MINISTER != A.PRIME_MINISTER,
LIKE_FIRST as PRIME_MINISTER = A.PRIME_MINISTER
)
ORDER BY MATCH#,START_DATE;
This presentation is available in http://db-oriented.com/presentations
©OrenNakdimon©OrenNakdimon
SELECT *
FROM ISRAEL_CABINETS
MATCH_RECOGNIZE (
ORDER BY START_DATE, END_DATE
MEASURES
MATCH_NUMBER() match#,
CLASSIFIER() cls,
END_DATE - START_DATE days,
FINAL AVG(DIFF.END_DATE – DIFF.START_DATE) avg_days
ALL ROWS PER MATCH
AFTER MATCH SKIP TO FIRST DIFF
PATTERN (A SAME* DIFF+ LIKE_FIRST+)
DEFINE
SAME as PRIME_MINISTER = PREV(PRIME_MINISTER),
DIFF as PRIME_MINISTER != A.PRIME_MINISTER,
LIKE_FIRST as PRIME_MINISTER = A.PRIME_MINISTER
)
ORDER BY MATCH#,START_DATE;
This presentation is available in http://db-oriented.com/presentations
©OrenNakdimon©OrenNakdimon
SELECT *
FROM ISRAEL_CABINETS
MATCH_RECOGNIZE (
ORDER BY START_DATE, END_DATE
MEASURES
MATCH_NUMBER() match#,
CLASSIFIER() cls,
END_DATE - START_DATE days,
FINAL AVG(THE_PM.END_DATE – THE_PM.START_DATE) avg_days
ALL ROWS PER MATCH
AFTER MATCH SKIP TO FIRST DIFF
PATTERN (A SAME* DIFF+ LIKE_FIRST+)
SUBSET THE_PM = (A, SAME, LIKE_FIRST)
DEFINE
SAME as PRIME_MINISTER = PREV(PRIME_MINISTER),
DIFF as PRIME_MINISTER != A.PRIME_MINISTER,
LIKE_FIRST as PRIME_MINISTER = A.PRIME_MINISTER
)
ORDER BY MATCH#,START_DATE;
THANK YOU
Oren Nakdimon
www.db-oriented.com
 oren@db-oriented.com
 +972-54-4393763
@DBoriented

More Related Content

Similar to Oren nakdimon - Oracle 12c SQL Pattern Matching Made Easy

SQL WORKSHOP::Lecture 12
SQL WORKSHOP::Lecture 12SQL WORKSHOP::Lecture 12
SQL WORKSHOP::Lecture 12Umair Amjad
 
Analytic functions in Oracle SQL - BIWA 2017
Analytic functions in Oracle SQL - BIWA 2017Analytic functions in Oracle SQL - BIWA 2017
Analytic functions in Oracle SQL - BIWA 2017Connor McDonald
 
DATABASE MANAGEMENT SYSTEM PRACTICAL LAB ASSIGNMENT 1
DATABASE MANAGEMENT SYSTEM PRACTICAL LAB ASSIGNMENT 1DATABASE MANAGEMENT SYSTEM PRACTICAL LAB ASSIGNMENT 1
DATABASE MANAGEMENT SYSTEM PRACTICAL LAB ASSIGNMENT 1Raj vardhan
 
Assignment 2 (16-08-2013)
Assignment 2 (16-08-2013)Assignment 2 (16-08-2013)
Assignment 2 (16-08-2013)Sanjay Pathak
 
capitalaim prm option
 capitalaim  prm option capitalaim  prm option
capitalaim prm optioncapitalaim
 
JCB VM166 D PD (Tier 2) VIBROMAX Parts Catalogue Manual (Serial Number 01800...
JCB VM166 D  PD (Tier 2) VIBROMAX Parts Catalogue Manual (Serial Number 01800...JCB VM166 D  PD (Tier 2) VIBROMAX Parts Catalogue Manual (Serial Number 01800...
JCB VM166 D PD (Tier 2) VIBROMAX Parts Catalogue Manual (Serial Number 01800...jdkskmdmmd
 
JCB VM166 D PD (Tier 2) VIBROMAX Parts Catalogue Manual (Serial Number 01807...
JCB VM166 D  PD (Tier 2) VIBROMAX Parts Catalogue Manual (Serial Number 01807...JCB VM166 D  PD (Tier 2) VIBROMAX Parts Catalogue Manual (Serial Number 01807...
JCB VM166 D PD (Tier 2) VIBROMAX Parts Catalogue Manual (Serial Number 01807...jdkskmdmmd
 
JCB VM166 D PD (Tier 2) VIBROMAX Parts Catalogue Manual (Serial Number 01800...
JCB VM166 D  PD (Tier 2) VIBROMAX Parts Catalogue Manual (Serial Number 01800...JCB VM166 D  PD (Tier 2) VIBROMAX Parts Catalogue Manual (Serial Number 01800...
JCB VM166 D PD (Tier 2) VIBROMAX Parts Catalogue Manual (Serial Number 01800...kdmra8udokmm
 
JCB VM166 D PD (Tier 2) VIBROMAX Parts Catalogue Manual (Serial Number 02150...
JCB VM166 D  PD (Tier 2) VIBROMAX Parts Catalogue Manual (Serial Number 02150...JCB VM166 D  PD (Tier 2) VIBROMAX Parts Catalogue Manual (Serial Number 02150...
JCB VM166 D PD (Tier 2) VIBROMAX Parts Catalogue Manual (Serial Number 02150...jdkskmdmmd
 

Similar to Oren nakdimon - Oracle 12c SQL Pattern Matching Made Easy (11)

SQL WORKSHOP::Lecture 12
SQL WORKSHOP::Lecture 12SQL WORKSHOP::Lecture 12
SQL WORKSHOP::Lecture 12
 
Analytic SQL Sep 2013
Analytic SQL Sep 2013Analytic SQL Sep 2013
Analytic SQL Sep 2013
 
Analytic functions in Oracle SQL - BIWA 2017
Analytic functions in Oracle SQL - BIWA 2017Analytic functions in Oracle SQL - BIWA 2017
Analytic functions in Oracle SQL - BIWA 2017
 
DATABASE MANAGEMENT SYSTEM PRACTICAL LAB ASSIGNMENT 1
DATABASE MANAGEMENT SYSTEM PRACTICAL LAB ASSIGNMENT 1DATABASE MANAGEMENT SYSTEM PRACTICAL LAB ASSIGNMENT 1
DATABASE MANAGEMENT SYSTEM PRACTICAL LAB ASSIGNMENT 1
 
Les12
Les12Les12
Les12
 
Assignment 2 (16-08-2013)
Assignment 2 (16-08-2013)Assignment 2 (16-08-2013)
Assignment 2 (16-08-2013)
 
capitalaim prm option
 capitalaim  prm option capitalaim  prm option
capitalaim prm option
 
JCB VM166 D PD (Tier 2) VIBROMAX Parts Catalogue Manual (Serial Number 01800...
JCB VM166 D  PD (Tier 2) VIBROMAX Parts Catalogue Manual (Serial Number 01800...JCB VM166 D  PD (Tier 2) VIBROMAX Parts Catalogue Manual (Serial Number 01800...
JCB VM166 D PD (Tier 2) VIBROMAX Parts Catalogue Manual (Serial Number 01800...
 
JCB VM166 D PD (Tier 2) VIBROMAX Parts Catalogue Manual (Serial Number 01807...
JCB VM166 D  PD (Tier 2) VIBROMAX Parts Catalogue Manual (Serial Number 01807...JCB VM166 D  PD (Tier 2) VIBROMAX Parts Catalogue Manual (Serial Number 01807...
JCB VM166 D PD (Tier 2) VIBROMAX Parts Catalogue Manual (Serial Number 01807...
 
JCB VM166 D PD (Tier 2) VIBROMAX Parts Catalogue Manual (Serial Number 01800...
JCB VM166 D  PD (Tier 2) VIBROMAX Parts Catalogue Manual (Serial Number 01800...JCB VM166 D  PD (Tier 2) VIBROMAX Parts Catalogue Manual (Serial Number 01800...
JCB VM166 D PD (Tier 2) VIBROMAX Parts Catalogue Manual (Serial Number 01800...
 
JCB VM166 D PD (Tier 2) VIBROMAX Parts Catalogue Manual (Serial Number 02150...
JCB VM166 D  PD (Tier 2) VIBROMAX Parts Catalogue Manual (Serial Number 02150...JCB VM166 D  PD (Tier 2) VIBROMAX Parts Catalogue Manual (Serial Number 02150...
JCB VM166 D PD (Tier 2) VIBROMAX Parts Catalogue Manual (Serial Number 02150...
 

More from Oren Nakdimon

Write Less (Code) With More (Features) [UKOUG 22]
Write Less (Code) With More (Features) [UKOUG 22]Write Less (Code) With More (Features) [UKOUG 22]
Write Less (Code) With More (Features) [UKOUG 22]Oren Nakdimon
 
Design Patterns in PLSQL and SQL [UKOUG 22]
Design Patterns in PLSQL and SQL [UKOUG 22]Design Patterns in PLSQL and SQL [UKOUG 22]
Design Patterns in PLSQL and SQL [UKOUG 22]Oren Nakdimon
 
Oren nakdimon - Write Less With More - UKOUGtogether21
Oren nakdimon - Write Less With More - UKOUGtogether21Oren nakdimon - Write Less With More - UKOUGtogether21
Oren nakdimon - Write Less With More - UKOUGtogether21Oren Nakdimon
 
Oren nakdimon - Design Patterns for PL/SQL and SQL - UKOUGtogether21
Oren nakdimon - Design Patterns for PL/SQL and SQL - UKOUGtogether21Oren nakdimon - Design Patterns for PL/SQL and SQL - UKOUGtogether21
Oren nakdimon - Design Patterns for PL/SQL and SQL - UKOUGtogether21Oren Nakdimon
 
Oren Nakdimon - Oracle SQL Pattern Matching Made Easy
Oren Nakdimon - Oracle SQL Pattern Matching Made EasyOren Nakdimon - Oracle SQL Pattern Matching Made Easy
Oren Nakdimon - Oracle SQL Pattern Matching Made EasyOren Nakdimon
 
Oracle Inter-Session Communication
Oracle Inter-Session CommunicationOracle Inter-Session Communication
Oracle Inter-Session CommunicationOren Nakdimon
 
Constraint Optimization
Constraint OptimizationConstraint Optimization
Constraint OptimizationOren Nakdimon
 
Edition Based Redefinition Made Easy - Oren Nakdimon
Edition Based Redefinition Made Easy - Oren NakdimonEdition Based Redefinition Made Easy - Oren Nakdimon
Edition Based Redefinition Made Easy - Oren NakdimonOren Nakdimon
 
Oren nakdimon oh really... i didn't know it is supported in standard edition
Oren nakdimon   oh really... i didn't know it is supported in standard editionOren nakdimon   oh really... i didn't know it is supported in standard edition
Oren nakdimon oh really... i didn't know it is supported in standard editionOren Nakdimon
 
Write Less (code) With More (Oracle Database 12c New Features)
Write Less (code) With More (Oracle Database 12c New Features)Write Less (code) With More (Oracle Database 12c New Features)
Write Less (code) With More (Oracle Database 12c New Features)Oren Nakdimon
 
Indexes and Indexing in Oracle 12c
Indexes and Indexing in Oracle 12cIndexes and Indexing in Oracle 12c
Indexes and Indexing in Oracle 12cOren Nakdimon
 
How to upgrade your application with no downtime (using edition-based redefin...
How to upgrade your application with no downtime (using edition-based redefin...How to upgrade your application with no downtime (using edition-based redefin...
How to upgrade your application with no downtime (using edition-based redefin...Oren Nakdimon
 
The Features That (maybe) You Didn't Know About
The Features That (maybe) You Didn't Know AboutThe Features That (maybe) You Didn't Know About
The Features That (maybe) You Didn't Know AboutOren Nakdimon
 

More from Oren Nakdimon (13)

Write Less (Code) With More (Features) [UKOUG 22]
Write Less (Code) With More (Features) [UKOUG 22]Write Less (Code) With More (Features) [UKOUG 22]
Write Less (Code) With More (Features) [UKOUG 22]
 
Design Patterns in PLSQL and SQL [UKOUG 22]
Design Patterns in PLSQL and SQL [UKOUG 22]Design Patterns in PLSQL and SQL [UKOUG 22]
Design Patterns in PLSQL and SQL [UKOUG 22]
 
Oren nakdimon - Write Less With More - UKOUGtogether21
Oren nakdimon - Write Less With More - UKOUGtogether21Oren nakdimon - Write Less With More - UKOUGtogether21
Oren nakdimon - Write Less With More - UKOUGtogether21
 
Oren nakdimon - Design Patterns for PL/SQL and SQL - UKOUGtogether21
Oren nakdimon - Design Patterns for PL/SQL and SQL - UKOUGtogether21Oren nakdimon - Design Patterns for PL/SQL and SQL - UKOUGtogether21
Oren nakdimon - Design Patterns for PL/SQL and SQL - UKOUGtogether21
 
Oren Nakdimon - Oracle SQL Pattern Matching Made Easy
Oren Nakdimon - Oracle SQL Pattern Matching Made EasyOren Nakdimon - Oracle SQL Pattern Matching Made Easy
Oren Nakdimon - Oracle SQL Pattern Matching Made Easy
 
Oracle Inter-Session Communication
Oracle Inter-Session CommunicationOracle Inter-Session Communication
Oracle Inter-Session Communication
 
Constraint Optimization
Constraint OptimizationConstraint Optimization
Constraint Optimization
 
Edition Based Redefinition Made Easy - Oren Nakdimon
Edition Based Redefinition Made Easy - Oren NakdimonEdition Based Redefinition Made Easy - Oren Nakdimon
Edition Based Redefinition Made Easy - Oren Nakdimon
 
Oren nakdimon oh really... i didn't know it is supported in standard edition
Oren nakdimon   oh really... i didn't know it is supported in standard editionOren nakdimon   oh really... i didn't know it is supported in standard edition
Oren nakdimon oh really... i didn't know it is supported in standard edition
 
Write Less (code) With More (Oracle Database 12c New Features)
Write Less (code) With More (Oracle Database 12c New Features)Write Less (code) With More (Oracle Database 12c New Features)
Write Less (code) With More (Oracle Database 12c New Features)
 
Indexes and Indexing in Oracle 12c
Indexes and Indexing in Oracle 12cIndexes and Indexing in Oracle 12c
Indexes and Indexing in Oracle 12c
 
How to upgrade your application with no downtime (using edition-based redefin...
How to upgrade your application with no downtime (using edition-based redefin...How to upgrade your application with no downtime (using edition-based redefin...
How to upgrade your application with no downtime (using edition-based redefin...
 
The Features That (maybe) You Didn't Know About
The Features That (maybe) You Didn't Know AboutThe Features That (maybe) You Didn't Know About
The Features That (maybe) You Didn't Know About
 

Recently uploaded

Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesKari Kakkonen
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Mark Goldstein
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch TuesdayIvanti
 
React Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App FrameworkReact Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App FrameworkPixlogix Infotech
 
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...Nikki Chapple
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
Generative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptxGenerative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptxfnnc6jmgwh
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI AgeCprime
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Alkin Tezuysal
 
Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationKnoldus Inc.
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsNathaniel Shimoni
 
QCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesQCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesBernd Ruecker
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS:  6 Ways to Automate Your Data IntegrationBridging Between CAD & GIS:  6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integrationmarketing932765
 

Recently uploaded (20)

Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examples
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch Tuesday
 
React Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App FrameworkReact Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App Framework
 
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
Generative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptxGenerative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptx
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI Age
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
 
Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog Presentation
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directions
 
QCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesQCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architectures
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS:  6 Ways to Automate Your Data IntegrationBridging Between CAD & GIS:  6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integration
 

Oren nakdimon - Oracle 12c SQL Pattern Matching Made Easy

  • 1. Oracle 12c SQL Pattern Matching Made Easy Oren Nakdimon www.db-oriented.com  oren@db-oriented.com  +972-54-4393763 @DBoriented
  • 2. This presentation is available in http://db-oriented.com/presentations ©OrenNakdimon©OrenNakdimon Which employees are in a specific department? How many times was Ben Gurion prime minister? Fibonacci (again?!?)
  • 3. This presentation is available in http://db-oriented.com/presentations ©OrenNakdimon©OrenNakdimon Who Am I? a chronology by “Oracle years” Where: IAF When: Oracle 6/7 [1991-1997] What: Developer Where: Golden Screens When: Oracle 8 [1997-1998] What: Server Group Manager Where: TELEknowledge When: Oracle 8i/9i [1998-2003] What: DBA Group Manager Where: Olista When: Oracle 10g/11g [2004-2011] What: VP R&D + Israel Site Manager
  • 4. This presentation is available in http://db-oriented.com/presentations ©OrenNakdimon©OrenNakdimon Database Architect / Developer / DBA Who Am I? a chronology by “Oracle years”
  • 5. This presentation is available in http://db-oriented.com/presentations ©OrenNakdimon©OrenNakdimon @DBoriented
  • 6. This presentation is available in http://db-oriented.com/presentations ©OrenNakdimon©OrenNakdimon http://db-oriented.com
  • 8. This presentation is available in http://db-oriented.com/presentations ©OrenNakdimon©OrenNakdimon The Most Basic SQL  Row-level visibility  Maximum one output row per input row  WHERE clause
  • 9. This presentation is available in http://db-oriented.com/presentations ©OrenNakdimon©OrenNakdimon Aggregate Functions  Group-level visibility  Strict definition of “group”  Each input row belongs to exactly one group  Maximum one output row per group  GROUP BY clause  HAVING clause
  • 10. This presentation is available in http://db-oriented.com/presentations ©OrenNakdimon©OrenNakdimon Analytic (Window) Functions  Window-level visibility  Strict definition of “window”  Each input row has its own window  Window-level aggregates are added to input rows  OVER  PARTITION BY  ORDER BY
  • 11. This presentation is available in http://db-oriented.com/presentations ©OrenNakdimon©OrenNakdimon Pattern Matching  Enhanced analysis of row sequences  Match-based output  One row per match (similar to the “group by” concept) or  All the match’s input rows (similar to the “window” concept)  Each input row may belong to 0, 1 or more matches
  • 12. This presentation is available in http://db-oriented.com/presentations ©OrenNakdimon©OrenNakdimon Find all the employees in department 30  The obvious solution is:  But that is too easy ;-) SELECT * FROM EMP WHERE DEPTNO = 30
  • 13. This presentation is available in http://db-oriented.com/presentations ©OrenNakdimon©OrenNakdimon Find all the employees in department 30 EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO 7369 SMITH CLERK 7902 17/12/1980 800 20 7499 ALLEN SALESMAN 7698 20/02/1981 1600 300 30 7521 WARD SALESMAN 7698 22/02/1981 1250 500 30 7566 JONES MANAGER 7839 02/04/1981 2975 20 7654 MARTIN SALESMAN 7698 28/09/1981 1250 1400 30 7698 BLAKE MANAGER 7839 01/05/1981 2850 30 7782 CLARK MANAGER 7839 09/06/1981 2450 10 7788 SCOTT ANALYST 7566 19/04/1987 3000 20 7839 KING PRESIDENT 17/11/1981 5000 10 7844 TURNER SALESMAN 7698 08/09/1981 1500 0 30 7876 ADAMS CLERK 7788 23/05/1987 1100 20 7900 JAMES CLERK 7698 03/12/1981 950 30 7902 FORD ANALYST 7566 03/12/1981 3000 20 7934 MILLER CLERK 7782 23/01/1982 1300 10 D30       Pattern Variable SELECT * FROM EMP MATCH_RECOGNIZE ( ALL ROWS PER MATCH PATTERN (D30) DEFINE D30 AS DEPTNO=30 ) 1 2 3 4 5 6
  • 14. This presentation is available in http://db-oriented.com/presentations ©OrenNakdimon©OrenNakdimon EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO 7369 SMITH CLERK 7902 17/12/1980 800 20 7499 ALLEN SALESMAN 7698 20/02/1981 1600 300 30 7521 WARD SALESMAN 7698 22/02/1981 1250 500 30 7566 JONES MANAGER 7839 02/04/1981 2975 20 7698 BLAKE MANAGER 7839 01/05/1981 2850 30 7782 CLARK MANAGER 7839 09/06/1981 2450 10 7844 TURNER SALESMAN 7698 08/09/1981 1500 0 30 7654 MARTIN SALESMAN 7698 28/09/1981 1250 1400 30 7839 KING PRESIDENT 17/11/1981 5000 10 7900 JAMES CLERK 7698 03/12/1981 950 30 7902 FORD ANALYST 7566 03/12/1981 3000 20 7934 MILLER CLERK 7782 23/01/1982 1300 10 7788 SCOTT ANALYST 7566 19/04/1987 3000 20 7876 ADAMS CLERK 7788 23/05/1987 1100 20 SELECT * FROM EMP MATCH_RECOGNIZE ( ORDER BY HIREDATE ALL ROWS PER MATCH PATTERN (D30 D30) DEFINE D30 AS DEPTNO=30 ) D30 Find 2 employees hired successively to department 30       Pattern Variableorder by 1 2
  • 15. This presentation is available in http://db-oriented.com/presentations ©OrenNakdimon©OrenNakdimon EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO 7369 SMITH CLERK 7902 17/12/1980 800 20 7499 ALLEN SALESMAN 7698 20/02/1981 1600 300 30 7521 WARD SALESMAN 7698 22/02/1981 1250 500 30 7566 JONES MANAGER 7839 02/04/1981 2975 20 7698 BLAKE MANAGER 7839 01/05/1981 2850 30 7782 CLARK MANAGER 7839 09/06/1981 2450 10 7844 TURNER SALESMAN 7698 08/09/1981 1500 0 30 7654 MARTIN SALESMAN 7698 28/09/1981 1250 1400 30 7839 KING PRESIDENT 17/11/1981 5000 10 7900 JAMES CLERK 7698 03/12/1981 950 30 7902 FORD ANALYST 7566 03/12/1981 3000 20 7934 MILLER CLERK 7782 23/01/1982 1300 10 7788 SCOTT ANALYST 7566 19/04/1987 3000 20 7876 ADAMS CLERK 7788 23/05/1987 1100 20 SELECT * FROM EMP MATCH_RECOGNIZE ( ORDER BY HIREDATE ALL ROWS PER MATCH PATTERN (D30{2}) DEFINE D30 AS DEPTNO=30 ) D30 Find 2 employees hired successively to department 30       Pattern Variableorder by 1 2
  • 16. This presentation is available in http://db-oriented.com/presentations ©OrenNakdimon©OrenNakdimon PATTERN Quantifiers Pattern Number of consecutive occurrences X 1 X{n} n X+ 1 or more X{n,} n or more X{n,m} between n and m X{,m} between 0 and m X* 0 or more X? 0 or 1
  • 17. This presentation is available in http://db-oriented.com/presentations ©OrenNakdimon©OrenNakdimon EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO 7369 SMITH CLERK 7902 17/12/1980 800 20 7499 ALLEN SALESMAN 7698 20/02/1981 1600 300 30 7521 WARD SALESMAN 7698 22/02/1981 1250 500 30 7566 JONES MANAGER 7839 02/04/1981 2975 20 7698 BLAKE MANAGER 7839 01/05/1981 2850 30 7782 CLARK MANAGER 7839 09/06/1981 2450 10 7844 TURNER SALESMAN 7698 08/09/1981 1500 0 30 7654 MARTIN SALESMAN 7698 28/09/1981 1250 1400 30 7839 KING PRESIDENT 17/11/1981 5000 10 7900 JAMES CLERK 7698 03/12/1981 950 30 7902 FORD ANALYST 7566 03/12/1981 3000 20 7934 MILLER CLERK 7782 23/01/1982 1300 10 7788 SCOTT ANALYST 7566 19/04/1987 3000 20 7876 ADAMS CLERK 7788 23/05/1987 1100 20 SELECT * FROM EMP MATCH_RECOGNIZE ( ORDER BY HIREDATE ALL ROWS PER MATCH PATTERN (D30+) DEFINE D30 AS DEPTNO=30 ) D30 Find one or more employees hired successively to department 30       Pattern Variableorder by 1 2 3 4
  • 18. This presentation is available in http://db-oriented.com/presentations ©OrenNakdimon©OrenNakdimon EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO 7369 SMITH CLERK 7902 17/12/1980 800 20 7499 ALLEN SALESMAN 7698 20/02/1981 1600 300 30 7521 WARD SALESMAN 7698 22/02/1981 1250 500 30 7566 JONES MANAGER 7839 02/04/1981 2975 20 7698 BLAKE MANAGER 7839 01/05/1981 2850 30 7782 CLARK MANAGER 7839 09/06/1981 2450 10 7844 TURNER SALESMAN 7698 08/09/1981 1500 0 30 7654 MARTIN SALESMAN 7698 28/09/1981 1250 1400 30 7839 KING PRESIDENT 17/11/1981 5000 10 7900 JAMES CLERK 7698 03/12/1981 950 30 7902 FORD ANALYST 7566 03/12/1981 3000 20 7934 MILLER CLERK 7782 23/01/1982 1300 10 7788 SCOTT ANALYST 7566 19/04/1987 3000 20 7876 ADAMS CLERK 7788 23/05/1987 1100 20 D30 Multiple Pattern Variables       Pattern Variables D20 LS             SELECT * FROM EMP MATCH_RECOGNIZE ( ORDER BY HIREDATE ALL ROWS PER MATCH PATTERN (D30 D20 LS?) DEFINE D30 AS DEPTNO=30, D20 AS DEPTNO=20, LS AS SAL<=1500 ) order by
  • 19. This presentation is available in http://db-oriented.com/presentations ©OrenNakdimon©OrenNakdimon EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO 7369 SMITH CLERK 7902 17/12/1980 800 20 7499 ALLEN SALESMAN 7698 20/02/1981 1600 300 30 7521 WARD SALESMAN 7698 22/02/1981 1250 500 30 7566 JONES MANAGER 7839 02/04/1981 2975 20 7698 BLAKE MANAGER 7839 01/05/1981 2850 30 7782 CLARK MANAGER 7839 09/06/1981 2450 10 7844 TURNER SALESMAN 7698 08/09/1981 1500 0 30 7654 MARTIN SALESMAN 7698 28/09/1981 1250 1400 30 7839 KING PRESIDENT 17/11/1981 5000 10 7900 JAMES CLERK 7698 03/12/1981 950 30 7902 FORD ANALYST 7566 03/12/1981 3000 20 7934 MILLER CLERK 7782 23/01/1982 1300 10 7788 SCOTT ANALYST 7566 19/04/1987 3000 20 7876 ADAMS CLERK 7788 23/05/1987 1100 20 D30 Multiple Pattern Variables   Pattern Variables D20 LS    SELECT * FROM EMP MATCH_RECOGNIZE ( ORDER BY HIREDATE ALL ROWS PER MATCH PATTERN (D30 D20 LS?) DEFINE D30 AS DEPTNO=30, D20 AS DEPTNO=20, LS AS SAL<=1500 ) order by
  • 20. This presentation is available in http://db-oriented.com/presentations ©OrenNakdimon©OrenNakdimon Dividing the Input Row Set EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO 7782 CLARK MANAGER 7839 09/06/1981 2450 10 7839 KING PRESIDENT 17/11/1981 5000 10 7934 MILLER CLERK 7782 23/01/1982 1300 10 7369 SMITH CLERK 7902 17/12/1980 800 20 7566 JONES MANAGER 7839 02/04/1981 2975 20 7902 FORD ANALYST 7566 03/12/1981 3000 20 7788 SCOTT ANALYST 7566 19/04/1987 3000 20 7876 ADAMS CLERK 7788 23/05/1987 1100 20 7499 ALLEN SALESMAN 7698 20/02/1981 1600 300 30 7521 WARD SALESMAN 7698 22/02/1981 1250 500 30 7698 BLAKE MANAGER 7839 01/05/1981 2850 30 7844 TURNER SALESMAN 7698 08/09/1981 1500 0 30 7654 MARTIN SALESMAN 7698 28/09/1981 1250 1400 30 7900 JAMES CLERK 7698 03/12/1981 950 30 HS   LS             order by partition by Pattern Variables SELECT * FROM EMP MATCH_RECOGNIZE ( PARTITION BY DEPTNO ORDER BY HIREDATE ALL ROWS PER MATCH PATTERN (HS+ LS*) DEFINE LS AS SAL<=1500, HS AS SAL> 1500 )
  • 21. This presentation is available in http://db-oriented.com/presentations ©OrenNakdimon©OrenNakdimon Dividing the Input Row Set EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO 7782 CLARK MANAGER 7839 09/06/1981 2450 10 7839 KING PRESIDENT 17/11/1981 5000 10 7934 MILLER CLERK 7782 23/01/1982 1300 10 7369 SMITH CLERK 7902 17/12/1980 800 20 7566 JONES MANAGER 7839 02/04/1981 2975 20 7902 FORD ANALYST 7566 03/12/1981 3000 20 7788 SCOTT ANALYST 7566 19/04/1987 3000 20 7876 ADAMS CLERK 7788 23/05/1987 1100 20 7499 ALLEN SALESMAN 7698 20/02/1981 1600 300 30 7521 WARD SALESMAN 7698 22/02/1981 1250 500 30 7698 BLAKE MANAGER 7839 01/05/1981 2850 30 7844 TURNER SALESMAN 7698 08/09/1981 1500 0 30 7654 MARTIN SALESMAN 7698 28/09/1981 1250 1400 30 7900 JAMES CLERK 7698 03/12/1981 950 30 HS   LS             order by partition by Pattern Variables SELECT * FROM EMP MATCH_RECOGNIZE ( PARTITION BY DEPTNO ORDER BY HIREDATE ALL ROWS PER MATCH PATTERN (HS+ LS*) DEFINE LS AS SAL<=1500, HS AS SAL> 1500 )
  • 22. This presentation is available in http://db-oriented.com/presentations ©OrenNakdimon©OrenNakdimon Adding Measures EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO 7782 CLARK MANAGER 7839 09/06/1981 2450 10 7839 KING PRESIDENT 17/11/1981 5000 10 7934 MILLER CLERK 7782 23/01/1982 1300 10 7369 SMITH CLERK 7902 17/12/1980 800 20 7566 JONES MANAGER 7839 02/04/1981 2975 20 7902 FORD ANALYST 7566 03/12/1981 3000 20 7788 SCOTT ANALYST 7566 19/04/1987 3000 20 7876 ADAMS CLERK 7788 23/05/1987 1100 20 7499 ALLEN SALESMAN 7698 20/02/1981 1600 300 30 7521 WARD SALESMAN 7698 22/02/1981 1250 500 30 7698 BLAKE MANAGER 7839 01/05/1981 2850 30 7844 TURNER SALESMAN 7698 08/09/1981 1500 0 30 7654 MARTIN SALESMAN 7698 28/09/1981 1250 1400 30 7900 JAMES CLERK 7698 03/12/1981 950 30 HS   LS             order by partition by Pattern Variables SELECT * FROM EMP MATCH_RECOGNIZE ( PARTITION BY DEPTNO ORDER BY HIREDATE MEASURES MATCH_NUMBER() as MATCH# ALL ROWS PER MATCH PATTERN (HS+ LS*) DEFINE LS AS SAL<=1500, HS AS SAL> 1500 )
  • 23. This presentation is available in http://db-oriented.com/presentations ©OrenNakdimon©OrenNakdimon EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO 7782 CLARK MANAGER 7839 09/06/1981 2450 10 7839 KING PRESIDENT 17/11/1981 5000 10 7934 MILLER CLERK 7782 23/01/1982 1300 10 7369 SMITH CLERK 7902 17/12/1980 800 20 7566 JONES MANAGER 7839 02/04/1981 2975 20 7902 FORD ANALYST 7566 03/12/1981 3000 20 7788 SCOTT ANALYST 7566 19/04/1987 3000 20 7876 ADAMS CLERK 7788 23/05/1987 1100 20 7499 ALLEN SALESMAN 7698 20/02/1981 1600 300 30 7521 WARD SALESMAN 7698 22/02/1981 1250 500 30 7698 BLAKE MANAGER 7839 01/05/1981 2850 30 7844 TURNER SALESMAN 7698 08/09/1981 1500 0 30 7654 MARTIN SALESMAN 7698 28/09/1981 1250 1400 30 7900 JAMES CLERK 7698 03/12/1981 950 30 Adding Measures HS   LS             order by partition by Pattern Variables SELECT * FROM EMP MATCH_RECOGNIZE ( PARTITION BY DEPTNO ORDER BY HIREDATE MEASURES MATCH_NUMBER() as MATCH# ALL ROWS PER MATCH AFTER MATCH SKIP PAST LAST ROW PATTERN (HS+ LS*) DEFINE LS AS SAL<=1500, HS AS SAL> 1500 )
  • 24. This presentation is available in http://db-oriented.com/presentations ©OrenNakdimon©OrenNakdimon AFTER MATCH SKIP  PAST LAST ROW (the default)  TO NEXT ROW  TO FIRST var  TO [LAST] var
  • 25. This presentation is available in http://db-oriented.com/presentations ©OrenNakdimon©OrenNakdimon Adding Measures EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO 7782 CLARK MANAGER 7839 09/06/1981 2450 10 7839 KING PRESIDENT 17/11/1981 5000 10 7934 MILLER CLERK 7782 23/01/1982 1300 10 7369 SMITH CLERK 7902 17/12/1980 800 20 7566 JONES MANAGER 7839 02/04/1981 2975 20 7902 FORD ANALYST 7566 03/12/1981 3000 20 7788 SCOTT ANALYST 7566 19/04/1987 3000 20 7876 ADAMS CLERK 7788 23/05/1987 1100 20 7499 ALLEN SALESMAN 7698 20/02/1981 1600 300 30 7521 WARD SALESMAN 7698 22/02/1981 1250 500 30 7698 BLAKE MANAGER 7839 01/05/1981 2850 30 7844 TURNER SALESMAN 7698 08/09/1981 1500 0 30 7654 MARTIN SALESMAN 7698 28/09/1981 1250 1400 30 7900 JAMES CLERK 7698 03/12/1981 950 30 HS   LS             order by partition by Pattern Variables SELECT * FROM EMP MATCH_RECOGNIZE ( PARTITION BY DEPTNO ORDER BY HIREDATE MEASURES MATCH_NUMBER() as MATCH# ALL ROWS PER MATCH PATTERN (HS+ LS*) DEFINE LS AS SAL<=1500, HS AS SAL> 1500 ) SELECT * FROM EMP MATCH_RECOGNIZE ( PARTITION BY DEPTNO ORDER BY HIREDATE MEASURES MATCH_NUMBER() as MATCH# ALL ROWS PER MATCH AFTER MATCH SKIP TO NEXT ROW PATTERN (HS+ LS*) DEFINE LS AS SAL<=1500, HS AS SAL> 1500 )
  • 26. This presentation is available in http://db-oriented.com/presentations ©OrenNakdimon©OrenNakdimon Adding Measures EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO 7782 CLARK MANAGER 7839 09/06/1981 2450 10 7839 KING PRESIDENT 17/11/1981 5000 10 7934 MILLER CLERK 7782 23/01/1982 1300 10 7369 SMITH CLERK 7902 17/12/1980 800 20 7566 JONES MANAGER 7839 02/04/1981 2975 20 7902 FORD ANALYST 7566 03/12/1981 3000 20 7788 SCOTT ANALYST 7566 19/04/1987 3000 20 7876 ADAMS CLERK 7788 23/05/1987 1100 20 7499 ALLEN SALESMAN 7698 20/02/1981 1600 300 30 7521 WARD SALESMAN 7698 22/02/1981 1250 500 30 7698 BLAKE MANAGER 7839 01/05/1981 2850 30 7844 TURNER SALESMAN 7698 08/09/1981 1500 0 30 7654 MARTIN SALESMAN 7698 28/09/1981 1250 1400 30 7900 JAMES CLERK 7698 03/12/1981 950 30 HS   LS             order by partition by Pattern Variables SELECT * FROM EMP MATCH_RECOGNIZE ( PARTITION BY DEPTNO ORDER BY HIREDATE MEASURES MATCH_NUMBER() as MATCH# ALL ROWS PER MATCH PATTERN (HS+ LS*) DEFINE LS AS SAL<=1500, HS AS SAL> 1500 ) SELECT * FROM EMP MATCH_RECOGNIZE ( PARTITION BY DEPTNO ORDER BY HIREDATE MEASURES MATCH_NUMBER() as MATCH# ALL ROWS PER MATCH AFTER MATCH SKIP TO NEXT ROW PATTERN (HS+ LS*) DEFINE LS AS SAL<=1500, HS AS SAL> 1500 )
  • 27. This presentation is available in http://db-oriented.com/presentations ©OrenNakdimon©OrenNakdimon Uniting Adjacent Periods KNESSET_ NUMBER PRIME_MINISTER START_DATE END_DATE 0 ‫בן‬ ‫דוד‬-‫גוריון‬ 14/05/1948 10/03/1949 1 ‫בן‬ ‫דוד‬-‫גוריון‬ 10/03/1949 01/11/1950 1 ‫בן‬ ‫דוד‬-‫גוריון‬ 01/11/1950 08/10/1951 2 ‫בן‬ ‫דוד‬-‫גוריון‬ 08/10/1951 24/12/1952 2 ‫בן‬ ‫דוד‬-‫גוריון‬ 24/12/1952 26/01/1954 2 ‫שרת‬ ‫משה‬ 26/01/1954 29/06/1955 2 ‫שרת‬ ‫משה‬ 29/06/1955 03/11/1955 3 ‫בן‬ ‫דוד‬-‫גוריון‬ 03/11/1955 07/01/1958 3 ‫בן‬ ‫דוד‬-‫גוריון‬ 07/01/1958 17/12/1959 4 ‫בן‬ ‫דוד‬-‫גוריון‬ 17/12/1959 02/11/1961 5 ‫בן‬ ‫דוד‬-‫גוריון‬ 02/11/1961 26/06/1963 5 ‫אשכול‬ ‫לוי‬ 26/06/1963 22/12/1964 5 ‫אשכול‬ ‫לוי‬ 22/12/1964 12/01/1966 6 ‫אשכול‬ ‫לוי‬ 12/01/1966 26/02/1969 6 ‫מאיר‬ ‫גולדה‬ 17/03/1969 15/12/1969 7 ‫מאיר‬ ‫גולדה‬ 15/12/1969 10/03/1974 8 ‫מאיר‬ ‫גולדה‬ 10/03/1974 03/06/1974 8 ‫רבין‬ ‫יצחק‬ 03/06/1974 20/06/1977 9 ‫בגין‬ ‫מנחם‬ 20/06/1977 05/08/1981 10 ‫בגין‬ ‫מנחם‬ 05/08/1981 10/10/1983 10 ‫שמיר‬ ‫יצחק‬ 10/10/1983 13/09/1984 11 ‫פרס‬ ‫שמעון‬ 13/09/1984 20/10/1986 11 ‫שמיר‬ ‫יצחק‬ 20/10/1986 22/12/1988 12 ‫שמיר‬ ‫יצחק‬ 22/12/1988 11/06/1990 12 ‫שמיר‬ ‫יצחק‬ 11/06/1990 13/07/1992 13 ‫רבין‬ ‫יצחק‬ 13/07/1992 04/11/1995 13 ‫פרס‬ ‫שמעון‬ 22/11/1995 18/06/1996 14 ‫נתניהו‬ ‫בנימין‬ 18/06/1996 06/07/1999 15 ‫ברק‬ ‫אהוד‬ 06/07/1999 07/03/2001 15 ‫שרון‬ ‫אריאל‬ 07/03/2001 28/02/2003 16 ‫שרון‬ ‫אריאל‬ 28/02/2003 16/04/2006 17 ‫אולמרט‬ ‫אהוד‬ 04/05/2006 31/03/2009 18 ‫נתניהו‬ ‫בנימין‬ 31/03/2009 18/03/2013 19 ‫נתניהו‬ ‫בנימין‬ 18/03/2013 14/05/2015 20 ‫נתניהו‬ ‫בנימין‬ 14/05/2015
  • 28. This presentation is available in http://db-oriented.com/presentations ©OrenNakdimon©OrenNakdimon Uniting Adjacent Periods KNESSET_ NUMBER PRIME_MINISTER START_DATE END_DATE 0 ‫בן‬ ‫דוד‬-‫גוריון‬ 14/05/1948 10/03/1949 1 ‫בן‬ ‫דוד‬-‫גוריון‬ 10/03/1949 01/11/1950 1 ‫בן‬ ‫דוד‬-‫גוריון‬ 01/11/1950 08/10/1951 2 ‫בן‬ ‫דוד‬-‫גוריון‬ 08/10/1951 24/12/1952 2 ‫בן‬ ‫דוד‬-‫גוריון‬ 24/12/1952 26/01/1954 2 ‫שרת‬ ‫משה‬ 26/01/1954 29/06/1955 2 ‫שרת‬ ‫משה‬ 29/06/1955 03/11/1955 3 ‫בן‬ ‫דוד‬-‫גוריון‬ 03/11/1955 07/01/1958 3 ‫בן‬ ‫דוד‬-‫גוריון‬ 07/01/1958 17/12/1959 4 ‫בן‬ ‫דוד‬-‫גוריון‬ 17/12/1959 02/11/1961 5 ‫בן‬ ‫דוד‬-‫גוריון‬ 02/11/1961 26/06/1963 5 ‫אשכול‬ ‫לוי‬ 26/06/1963 22/12/1964 5 ‫אשכול‬ ‫לוי‬ 22/12/1964 12/01/1966 6 ‫אשכול‬ ‫לוי‬ 12/01/1966 26/02/1969 6 ‫מאיר‬ ‫גולדה‬ 17/03/1969 15/12/1969 7 ‫מאיר‬ ‫גולדה‬ 15/12/1969 10/03/1974 8 ‫מאיר‬ ‫גולדה‬ 10/03/1974 03/06/1974 8 ‫רבין‬ ‫יצחק‬ 03/06/1974 20/06/1977 9 ‫בגין‬ ‫מנחם‬ 20/06/1977 05/08/1981 10 ‫בגין‬ ‫מנחם‬ 05/08/1981 10/10/1983 10 ‫שמיר‬ ‫יצחק‬ 10/10/1983 13/09/1984 11 ‫פרס‬ ‫שמעון‬ 13/09/1984 20/10/1986 11 ‫שמיר‬ ‫יצחק‬ 20/10/1986 22/12/1988 12 ‫שמיר‬ ‫יצחק‬ 22/12/1988 11/06/1990 12 ‫שמיר‬ ‫יצחק‬ 11/06/1990 13/07/1992 13 ‫רבין‬ ‫יצחק‬ 13/07/1992 04/11/1995 13 ‫פרס‬ ‫שמעון‬ 22/11/1995 18/06/1996 14 ‫נתניהו‬ ‫בנימין‬ 18/06/1996 06/07/1999 15 ‫ברק‬ ‫אהוד‬ 06/07/1999 07/03/2001 15 ‫שרון‬ ‫אריאל‬ 07/03/2001 28/02/2003 16 ‫שרון‬ ‫אריאל‬ 28/02/2003 16/04/2006 17 ‫אולמרט‬ ‫אהוד‬ 04/05/2006 31/03/2009 18 ‫נתניהו‬ ‫בנימין‬ 31/03/2009 18/03/2013 19 ‫נתניהו‬ ‫בנימין‬ 18/03/2013 14/05/2015 20 ‫נתניהו‬ ‫בנימין‬ 14/05/2015
  • 29. This presentation is available in http://db-oriented.com/presentations ©OrenNakdimon©OrenNakdimon KNESSET_ NUMBER PRIME_MINISTER START_DATE END_DATE 17 ‫אולמרט‬ ‫אהוד‬ 04/05/2006 31/03/2009 15 ‫ברק‬ ‫אהוד‬ 06/07/1999 07/03/2001 15 ‫שרון‬ ‫אריאל‬ 07/03/2001 28/02/2003 16 ‫שרון‬ ‫אריאל‬ 28/02/2003 16/04/2006 14 ‫נתניהו‬ ‫בנימין‬ 18/06/1996 06/07/1999 18 ‫נתניהו‬ ‫בנימין‬ 31/03/2009 18/03/2013 19 ‫נתניהו‬ ‫בנימין‬ 18/03/2013 14/05/2015 20 ‫נתניהו‬ ‫בנימין‬ 14/05/2015 6 ‫מאיר‬ ‫גולדה‬ 17/03/1969 15/12/1969 7 ‫מאיר‬ ‫גולדה‬ 15/12/1969 10/03/1974 8 ‫מאיר‬ ‫גולדה‬ 10/03/1974 03/06/1974 0 ‫בן‬ ‫דוד‬-‫גוריון‬ 14/05/1948 10/03/1949 1 ‫בן‬ ‫דוד‬-‫גוריון‬ 10/03/1949 01/11/1950 1 ‫בן‬ ‫דוד‬-‫גוריון‬ 01/11/1950 08/10/1951 2 ‫בן‬ ‫דוד‬-‫גוריון‬ 08/10/1951 24/12/1952 2 ‫בן‬ ‫דוד‬-‫גוריון‬ 24/12/1952 26/01/1954 3 ‫בן‬ ‫דוד‬-‫גוריון‬ 03/11/1955 07/01/1958 3 ‫בן‬ ‫דוד‬-‫גוריון‬ 07/01/1958 17/12/1959 4 ‫בן‬ ‫דוד‬-‫גוריון‬ 17/12/1959 02/11/1961 5 ‫בן‬ ‫דוד‬-‫גוריון‬ 02/11/1961 26/06/1963 8 ‫רבין‬ ‫יצחק‬ 03/06/1974 20/06/1977 13 ‫רבין‬ ‫יצחק‬ 13/07/1992 04/11/1995 partition by NXT             order by
  • 30. This presentation is available in http://db-oriented.com/presentations ©OrenNakdimon©OrenNakdimon SELECT * FROM ISRAEL_CABINETS MATCH_RECOGNIZE ( PARTITION BY PRIME_MINISTER ORDER BY START_DATE, END_DATE MEASURES MATCH_NUMBER() CONT_PERIOD# ALL ROWS PER MATCH PATTERN (STRT NXT*) DEFINE NXT AS START_DATE = PREV(END_DATE) ) ORDER BY START_DATE; And if we want at least two tenures?
  • 31. This presentation is available in http://db-oriented.com/presentations ©OrenNakdimon©OrenNakdimon SELECT * FROM ISRAEL_CABINETS MATCH_RECOGNIZE ( PARTITION BY PRIME_MINISTER ORDER BY START_DATE, END_DATE MEASURES MATCH_NUMBER() CONT_PERIOD# ALL ROWS PER MATCH PATTERN (STRT NXT+) DEFINE NXT AS START_DATE = PREV(END_DATE) ) ORDER BY START_DATE;
  • 32. This presentation is available in http://db-oriented.com/presentations ©OrenNakdimon©OrenNakdimon SELECT * FROM ISRAEL_CABINETS MATCH_RECOGNIZE ( PARTITION BY PRIME_MINISTER ORDER BY START_DATE, END_DATE MEASURES MATCH_NUMBER() CONT_PERIOD#, CLASSIFIER() CLS ALL ROWS PER MATCH PATTERN (STRT NXT*) DEFINE NXT AS START_DATE = PREV(END_DATE) ) ORDER BY START_DATE;
  • 33. This presentation is available in http://db-oriented.com/presentations ©OrenNakdimon©OrenNakdimon SELECT * FROM ISRAEL_CABINETS MATCH_RECOGNIZE ( PARTITION BY PRIME_MINISTER ORDER BY START_DATE, END_DATE MEASURES MATCH_NUMBER() CONT_PERIOD#, CLASSIFIER() CLS, END_DATE - START_DATE days_in_this_period ALL ROWS PER MATCH PATTERN (STRT NXT*) DEFINE NXT AS START_DATE = PREV(END_DATE) ) ORDER BY START_DATE;
  • 34. This presentation is available in http://db-oriented.com/presentations ©OrenNakdimon©OrenNakdimon SELECT * FROM ISRAEL_CABINETS MATCH_RECOGNIZE ( PARTITION BY PRIME_MINISTER ORDER BY START_DATE, END_DATE MEASURES MATCH_NUMBER() CONT_PERIOD#, CLASSIFIER() CLS, END_DATE - START_DATE days_in_this_period, END_DATE - STRT.START_DATE days_since_cont_period_start ALL ROWS PER MATCH PATTERN (STRT NXT*) DEFINE NXT AS START_DATE = PREV(END_DATE) ) ORDER BY START_DATE;
  • 35. This presentation is available in http://db-oriented.com/presentations ©OrenNakdimon©OrenNakdimon SELECT * FROM ISRAEL_CABINETS MATCH_RECOGNIZE ( PARTITION BY PRIME_MINISTER ORDER BY START_DATE, END_DATE MEASURES MATCH_NUMBER() CONT_PERIOD#, CLASSIFIER() CLS, END_DATE - START_DATE days_in_this_period, END_DATE - STRT.START_DATE days_since_cont_period_start, LAST(END_DATE) - FIRST(START_DATE) total_days ALL ROWS PER MATCH PATTERN (STRT NXT*) DEFINE NXT AS START_DATE = PREV(END_DATE) ) ORDER BY START_DATE;
  • 36. This presentation is available in http://db-oriented.com/presentations ©OrenNakdimon©OrenNakdimon SELECT * FROM ISRAEL_CABINETS MATCH_RECOGNIZE ( PARTITION BY PRIME_MINISTER ORDER BY START_DATE, END_DATE MEASURES MATCH_NUMBER() CONT_PERIOD#, CLASSIFIER() CLS, END_DATE - START_DATE days_in_this_period, END_DATE - STRT.START_DATE days_since_cont_period_start, RUNNING LAST(END_DATE) - FIRST(START_DATE) total_days ALL ROWS PER MATCH PATTERN (STRT NXT*) DEFINE NXT AS START_DATE = PREV(END_DATE) ) ORDER BY START_DATE;
  • 37. This presentation is available in http://db-oriented.com/presentations ©OrenNakdimon©OrenNakdimon SELECT * FROM ISRAEL_CABINETS MATCH_RECOGNIZE ( PARTITION BY PRIME_MINISTER ORDER BY START_DATE, END_DATE MEASURES MATCH_NUMBER() CONT_PERIOD#, CLASSIFIER() CLS, END_DATE - START_DATE days_in_this_period, END_DATE - STRT.START_DATE days_since_cont_period_start, FINAL LAST(END_DATE) - FIRST(START_DATE) total_days ALL ROWS PER MATCH PATTERN (STRT NXT*) DEFINE NXT AS START_DATE = PREV(END_DATE) ) ORDER BY START_DATE;
  • 38. This presentation is available in http://db-oriented.com/presentations ©OrenNakdimon©OrenNakdimon SELECT * FROM ISRAEL_CABINETS MATCH_RECOGNIZE ( PARTITION BY PRIME_MINISTER ORDER BY START_DATE MEASURES MATCH_NUMBER() cont_period#, FIRST(START_DATE) cont_period_start, LAST(END_DATE) cont_period_end, COUNT(*) num_of_periods ONE ROW PER MATCH PATTERN (STRT NXT*) DEFINE NXT AS START_DATE = PREV(END_DATE) ) ORDER BY CONT_PERIOD_START; COUNT MAX MIN SUM AVG
  • 39. This presentation is available in http://db-oriented.com/presentations ©OrenNakdimon©OrenNakdimon Find returning prime ministers after a break KNESSET_ NUMBER PRIME_MINISTER START_DATE END_DATE 0 ‫בן‬ ‫דוד‬-‫גוריון‬ 14/05/1948 10/03/1949 1 ‫בן‬ ‫דוד‬-‫גוריון‬ 10/03/1949 01/11/1950 1 ‫בן‬ ‫דוד‬-‫גוריון‬ 01/11/1950 08/10/1951 2 ‫בן‬ ‫דוד‬-‫גוריון‬ 08/10/1951 24/12/1952 2 ‫בן‬ ‫דוד‬-‫גוריון‬ 24/12/1952 26/01/1954 2 ‫שרת‬ ‫משה‬ 26/01/1954 29/06/1955 2 ‫שרת‬ ‫משה‬ 29/06/1955 03/11/1955 3 ‫בן‬ ‫דוד‬-‫גוריון‬ 03/11/1955 07/01/1958 3 ‫בן‬ ‫דוד‬-‫גוריון‬ 07/01/1958 17/12/1959 4 ‫בן‬ ‫דוד‬-‫גוריון‬ 17/12/1959 02/11/1961 5 ‫בן‬ ‫דוד‬-‫גוריון‬ 02/11/1961 26/06/1963 5 ‫אשכול‬ ‫לוי‬ 26/06/1963 22/12/1964 5 ‫אשכול‬ ‫לוי‬ 22/12/1964 12/01/1966 6 ‫אשכול‬ ‫לוי‬ 12/01/1966 26/02/1969 6 ‫מאיר‬ ‫גולדה‬ 17/03/1969 15/12/1969 7 ‫מאיר‬ ‫גולדה‬ 15/12/1969 10/03/1974 8 ‫מאיר‬ ‫גולדה‬ 10/03/1974 03/06/1974 8 ‫רבין‬ ‫יצחק‬ 03/06/1974 20/06/1977 9 ‫בגין‬ ‫מנחם‬ 20/06/1977 05/08/1981 10 ‫בגין‬ ‫מנחם‬ 05/08/1981 10/10/1983 10 ‫שמיר‬ ‫יצחק‬ 10/10/1983 13/09/1984 11 ‫פרס‬ ‫שמעון‬ 13/09/1984 20/10/1986 11 ‫שמיר‬ ‫יצחק‬ 20/10/1986 22/12/1988 12 ‫שמיר‬ ‫יצחק‬ 22/12/1988 11/06/1990 12 ‫שמיר‬ ‫יצחק‬ 11/06/1990 13/07/1992 13 ‫רבין‬ ‫יצחק‬ 13/07/1992 04/11/1995 13 ‫פרס‬ ‫שמעון‬ 22/11/1995 18/06/1996 14 ‫נתניהו‬ ‫בנימין‬ 18/06/1996 06/07/1999 15 ‫ברק‬ ‫אהוד‬ 06/07/1999 07/03/2001 15 ‫שרון‬ ‫אריאל‬ 07/03/2001 28/02/2003 16 ‫שרון‬ ‫אריאל‬ 28/02/2003 16/04/2006 17 ‫אולמרט‬ ‫אהוד‬ 04/05/2006 31/03/2009 18 ‫נתניהו‬ ‫בנימין‬ 31/03/2009 18/03/2013 19 ‫נתניהו‬ ‫בנימין‬ 18/03/2013 14/05/2015 20 ‫נתניהו‬ ‫בנימין‬ 14/05/2015
  • 40. This presentation is available in http://db-oriented.com/presentations ©OrenNakdimon©OrenNakdimon Find returning prime ministers after a break SELECT * FROM ISRAEL_CABINETS MATCH_RECOGNIZE ( ORDER BY START_DATE, END_DATE ALL ROWS PER MATCH PATTERN ( )
  • 41. This presentation is available in http://db-oriented.com/presentations ©OrenNakdimon©OrenNakdimon Find returning prime ministers after a break SELECT * FROM ISRAEL_CABINETS MATCH_RECOGNIZE ( ORDER BY START_DATE, END_DATE ALL ROWS PER MATCH PATTERN (A )
  • 42. This presentation is available in http://db-oriented.com/presentations ©OrenNakdimon©OrenNakdimon Find returning prime ministers after a break SELECT * FROM ISRAEL_CABINETS MATCH_RECOGNIZE ( ORDER BY START_DATE, END_DATE ALL ROWS PER MATCH PATTERN (A SAME* )
  • 43. This presentation is available in http://db-oriented.com/presentations ©OrenNakdimon©OrenNakdimon Find returning prime ministers after a break SELECT * FROM ISRAEL_CABINETS MATCH_RECOGNIZE ( ORDER BY START_DATE, END_DATE ALL ROWS PER MATCH PATTERN (A SAME* DIFF+ )
  • 44. This presentation is available in http://db-oriented.com/presentations ©OrenNakdimon©OrenNakdimon Find returning prime ministers after a break SELECT * FROM ISRAEL_CABINETS MATCH_RECOGNIZE ( ORDER BY START_DATE, END_DATE MEASURES MATCH_NUMBER() match#, CLASSIFIER() cls, COUNT(*) period#, COUNT(DIFF.*) diff_periods_until_now, FINAL COUNT(DIFF.*) total_diff_periods, END_DATE - START_DATE days ALL ROWS PER MATCH PATTERN (A SAME* DIFF+ LIKE_FIRST+) DEFINE SAME as SAME.PRIME_MINISTER = PREV(SAME.PRIME_MINISTER), DIFF as LAST(PRIME_MINISTER) != A.PRIME_MINISTER, LIKE_FIRST as PRIME_MINISTER = A.PRIME_MINISTER ) ORDER BY MATCH#,START_DATE;
  • 45. This presentation is available in http://db-oriented.com/presentations ©OrenNakdimon©OrenNakdimon COUNT(*) COUNT(DIFF.*) FINAL COUNT(DIFF.*)
  • 46. This presentation is available in http://db-oriented.com/presentations ©OrenNakdimon©OrenNakdimon Find returning prime ministers after a break SELECT * FROM ISRAEL_CABINETS MATCH_RECOGNIZE ( ORDER BY START_DATE, END_DATE MEASURES MATCH_NUMBER() match#, CLASSIFIER() cls, COUNT(*) period#, COUNT(DIFF.*) diff_periods_until_now, FINAL COUNT(DIFF.*) total_diff_periods, END_DATE - START_DATE days ALL ROWS PER MATCH AFTER MATCH SKIP TO FIRST DIFF PATTERN (A SAME* DIFF+ LIKE_FIRST+) DEFINE SAME as SAME.PRIME_MINISTER = PREV(SAME.PRIME_MINISTER), DIFF as LAST(PRIME_MINISTER) != A.PRIME_MINISTER, LIKE_FIRST as PRIME_MINISTER = A.PRIME_MINISTER ) ORDER BY MATCH#,START_DATE;
  • 47. This presentation is available in http://db-oriented.com/presentations ©OrenNakdimon©OrenNakdimon Find returning prime ministers after a break
  • 48. This presentation is available in http://db-oriented.com/presentations ©OrenNakdimon©OrenNakdimon Returning prime ministers after a break of exactly one other PM SELECT * FROM ISRAEL_CABINETS MATCH_RECOGNIZE ( ORDER BY START_DATE, END_DATE MEASURES MATCH_NUMBER() match#, CLASSIFIER() cls, COUNT(*) period# ALL ROWS PER MATCH AFTER MATCH SKIP TO FIRST DIFF PATTERN (A DEFINE SAME as SAME.PRIME_MINISTER = PREV(SAME.PRIME_MINISTER), DIFF as LAST(PRIME_MINISTER) != A.PRIME_MINISTER, LIKE_FIRST as PRIME_MINISTER = A.PRIME_MINISTER ) ORDER BY MATCH#,START_DATE;
  • 49. This presentation is available in http://db-oriented.com/presentations ©OrenNakdimon©OrenNakdimon Returning prime ministers after a break of exactly one other PM SELECT * FROM ISRAEL_CABINETS MATCH_RECOGNIZE ( ORDER BY START_DATE, END_DATE MEASURES MATCH_NUMBER() match#, CLASSIFIER() cls, COUNT(*) period# ALL ROWS PER MATCH AFTER MATCH SKIP TO FIRST DIFF PATTERN (A SAME* DEFINE SAME as SAME.PRIME_MINISTER = PREV(SAME.PRIME_MINISTER), DIFF as LAST(PRIME_MINISTER) != A.PRIME_MINISTER, LIKE_FIRST as PRIME_MINISTER = A.PRIME_MINISTER ) ORDER BY MATCH#,START_DATE;
  • 50. This presentation is available in http://db-oriented.com/presentations ©OrenNakdimon©OrenNakdimon Returning prime ministers after a break of exactly one other PM SELECT * FROM ISRAEL_CABINETS MATCH_RECOGNIZE ( ORDER BY START_DATE, END_DATE MEASURES MATCH_NUMBER() match#, CLASSIFIER() cls, COUNT(*) period# ALL ROWS PER MATCH AFTER MATCH SKIP TO FIRST DIFF PATTERN (A SAME* DIFF DEFINE SAME as SAME.PRIME_MINISTER = PREV(SAME.PRIME_MINISTER), DIFF as LAST(PRIME_MINISTER) != A.PRIME_MINISTER, LIKE_FIRST as PRIME_MINISTER = A.PRIME_MINISTER ) ORDER BY MATCH#,START_DATE;
  • 51. This presentation is available in http://db-oriented.com/presentations ©OrenNakdimon©OrenNakdimon Returning prime ministers after a break of exactly one other PM SELECT * FROM ISRAEL_CABINETS MATCH_RECOGNIZE ( ORDER BY START_DATE, END_DATE MEASURES MATCH_NUMBER() match#, CLASSIFIER() cls, COUNT(*) period# ALL ROWS PER MATCH AFTER MATCH SKIP TO FIRST DIFF PATTERN (A SAME* DIFF SAME* DEFINE SAME as SAME.PRIME_MINISTER = PREV(SAME.PRIME_MINISTER), DIFF as LAST(PRIME_MINISTER) != A.PRIME_MINISTER, LIKE_FIRST as PRIME_MINISTER = A.PRIME_MINISTER ) ORDER BY MATCH#,START_DATE;
  • 52. This presentation is available in http://db-oriented.com/presentations ©OrenNakdimon©OrenNakdimon Returning prime ministers after a break of exactly one other PM SELECT * FROM ISRAEL_CABINETS MATCH_RECOGNIZE ( ORDER BY START_DATE, END_DATE MEASURES MATCH_NUMBER() match#, CLASSIFIER() cls, COUNT(*) period# ALL ROWS PER MATCH AFTER MATCH SKIP TO FIRST DIFF PATTERN (A SAME* DIFF SAME* LIKE_FIRST DEFINE SAME as SAME.PRIME_MINISTER = PREV(SAME.PRIME_MINISTER), DIFF as LAST(PRIME_MINISTER) != A.PRIME_MINISTER, LIKE_FIRST as PRIME_MINISTER = A.PRIME_MINISTER ) ORDER BY MATCH#,START_DATE;
  • 53. This presentation is available in http://db-oriented.com/presentations ©OrenNakdimon©OrenNakdimon Returning prime ministers after a break of exactly one other PM SELECT * FROM ISRAEL_CABINETS MATCH_RECOGNIZE ( ORDER BY START_DATE, END_DATE MEASURES MATCH_NUMBER() match#, CLASSIFIER() cls, COUNT(*) period# ALL ROWS PER MATCH AFTER MATCH SKIP TO FIRST DIFF PATTERN (A SAME* DIFF SAME* LIKE_FIRST SAME*) DEFINE SAME as SAME.PRIME_MINISTER = PREV(SAME.PRIME_MINISTER), DIFF as LAST(PRIME_MINISTER) != A.PRIME_MINISTER, LIKE_FIRST as PRIME_MINISTER = A.PRIME_MINISTER ) ORDER BY MATCH#,START_DATE;
  • 54. This presentation is available in http://db-oriented.com/presentations ©OrenNakdimon©OrenNakdimon Returning prime ministers after a break of exactly one other PM SELECT * FROM ISRAEL_CABINETS MATCH_RECOGNIZE ( ORDER BY START_DATE, END_DATE MEASURES MATCH_NUMBER() match#, CLASSIFIER() cls, COUNT(*) period# ALL ROWS PER MATCH AFTER MATCH SKIP TO FIRST DIFF PATTERN (A SAME* DIFF SAME* LIKE_FIRST SAME*) DEFINE SAME as SAME.PRIME_MINISTER = PREV(SAME.PRIME_MINISTER), DIFF as LAST(PRIME_MINISTER) != A.PRIME_MINISTER, LIKE_FIRST as PRIME_MINISTER = A.PRIME_MINISTER ) ORDER BY MATCH#,START_DATE;
  • 55. This presentation is available in http://db-oriented.com/presentations ©OrenNakdimon©OrenNakdimon Fibonacci Numbers X 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 F        SELECT * FROM (select rownum X from dual connect by level<=100) MATCH_RECOGNIZE ( ORDER BY X MEASURES CLASSIFIER() AS F_OR_NOT ALL ROWS PER MATCH PATTERN ((F|NF)+) DEFINE F AS (X = 1 OR X = 2 OR X = LAST(F.X,1) + LAST(F.X,2)) ); Pattern Alternation
  • 56. This presentation is available in http://db-oriented.com/presentations ©OrenNakdimon©OrenNakdimon Only Fibonacci Numbers X 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 F        SELECT * FROM (select rownum X from dual connect by level<=100) MATCH_RECOGNIZE ( ORDER BY X MEASURES CLASSIFIER() AS F_OR_NOT ALL ROWS PER MATCH PATTERN ((F|{-NF-})+) DEFINE F AS (X = 1 OR X = 2 OR X = LAST(F.X,1) + LAST(F.X,2)) ); Pattern Exclusion
  • 57. This presentation is available in http://db-oriented.com/presentations ©OrenNakdimon©OrenNakdimon SELECT * FROM ISRAEL_CABINETS MATCH_RECOGNIZE ( ORDER BY START_DATE, END_DATE MEASURES MATCH_NUMBER() match#, CLASSIFIER() cls, END_DATE - START_DATE days ALL ROWS PER MATCH AFTER MATCH SKIP TO FIRST DIFF PATTERN (A SAME* DIFF+ LIKE_FIRST+) DEFINE SAME as PRIME_MINISTER = PREV(PRIME_MINISTER), DIFF as PRIME_MINISTER != A.PRIME_MINISTER, LIKE_FIRST as PRIME_MINISTER = A.PRIME_MINISTER ) ORDER BY MATCH#,START_DATE;
  • 58. This presentation is available in http://db-oriented.com/presentations ©OrenNakdimon©OrenNakdimon SELECT * FROM ISRAEL_CABINETS MATCH_RECOGNIZE ( ORDER BY START_DATE, END_DATE MEASURES MATCH_NUMBER() match#, CLASSIFIER() cls, END_DATE - START_DATE days, FINAL AVG(END_DATE - START_DATE) avg_days ALL ROWS PER MATCH AFTER MATCH SKIP TO FIRST DIFF PATTERN (A SAME* DIFF+ LIKE_FIRST+) DEFINE SAME as PRIME_MINISTER = PREV(PRIME_MINISTER), DIFF as PRIME_MINISTER != A.PRIME_MINISTER, LIKE_FIRST as PRIME_MINISTER = A.PRIME_MINISTER ) ORDER BY MATCH#,START_DATE;
  • 59. This presentation is available in http://db-oriented.com/presentations ©OrenNakdimon©OrenNakdimon SELECT * FROM ISRAEL_CABINETS MATCH_RECOGNIZE ( ORDER BY START_DATE, END_DATE MEASURES MATCH_NUMBER() match#, CLASSIFIER() cls, END_DATE - START_DATE days, FINAL AVG(DIFF.END_DATE – DIFF.START_DATE) avg_days ALL ROWS PER MATCH AFTER MATCH SKIP TO FIRST DIFF PATTERN (A SAME* DIFF+ LIKE_FIRST+) DEFINE SAME as PRIME_MINISTER = PREV(PRIME_MINISTER), DIFF as PRIME_MINISTER != A.PRIME_MINISTER, LIKE_FIRST as PRIME_MINISTER = A.PRIME_MINISTER ) ORDER BY MATCH#,START_DATE;
  • 60. This presentation is available in http://db-oriented.com/presentations ©OrenNakdimon©OrenNakdimon SELECT * FROM ISRAEL_CABINETS MATCH_RECOGNIZE ( ORDER BY START_DATE, END_DATE MEASURES MATCH_NUMBER() match#, CLASSIFIER() cls, END_DATE - START_DATE days, FINAL AVG(THE_PM.END_DATE – THE_PM.START_DATE) avg_days ALL ROWS PER MATCH AFTER MATCH SKIP TO FIRST DIFF PATTERN (A SAME* DIFF+ LIKE_FIRST+) SUBSET THE_PM = (A, SAME, LIKE_FIRST) DEFINE SAME as PRIME_MINISTER = PREV(PRIME_MINISTER), DIFF as PRIME_MINISTER != A.PRIME_MINISTER, LIKE_FIRST as PRIME_MINISTER = A.PRIME_MINISTER ) ORDER BY MATCH#,START_DATE;
  • 61. THANK YOU Oren Nakdimon www.db-oriented.com  oren@db-oriented.com  +972-54-4393763 @DBoriented