SlideShare a Scribd company logo
1 of 67
Download to read offline
Oracle
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
©
Oren
Nakdimon
©
Oren
Nakdimon
MATCH_RECOGNIZE
 Added in Oracle 12cR1
 Enhanced analysis of row sequences
 For detecting matches to complex patterns
 A significant boost to the analytical capabilities of SQL
 Very powerful
With Great
Power Comes
Complex
Syntax
This presentation is available in http://db-oriented.com/presentations
©
Oren
Nakdimon
©
Oren
Nakdimon
Agenda
 Start using Pattern Matching
 Step by step
 Not all the capabilities…
 But all the essentials (and more)
 Simple examples
 Recommended resources
This presentation is available in http://db-oriented.com/presentations
©
Oren
Nakdimon
©
Oren
Nakdimon
http://db-oriented.com
Who Am
I?
This presentation is available in http://db-oriented.com/presentations
©
Oren
Nakdimon
©
Oren
Nakdimon
1956 Switzerland Refrain Lys Assia French Switzerland
1957 Netherlands Net als toen Corry Brokken 31 Dutch Germany
1958 France Dors, mon amour André Claveau 27 French Netherlands
1959 Netherlands Een beetje Teddy Scholten 21 Dutch France
1960 France Tom Pillibi Jacqueline Boyer 32 French
United
Kingdom
1961 Luxembourg Nous les amoureux Jean-Claude Pascal 31 French France
1962 France Un premier amour Isabelle Aubret 26 French Luxembourg
1963 Denmark Dansevise Grethe and Jørgen Ingmann 42 Danish
United
Kingdom
1964 Italy Non ho l'età Gigliola Cinquetti 49 Italian Denmark
1965 Luxembourg
Poupée de cire, poupée
de son France Gall 32 French Italy
1966 Austria Merci, Chérie Udo Jürgens 31 German Luxembourg
1967
United
Kingdom Puppet on a String Sandie Shaw 47 English Austria
1968 Spain La, la, la Massiel 29 Spanish
United
Kingdom
1969 Netherlands De troubadour Lenny Kuhr 18 Dutch Spain
1970 Ireland
All Kinds of
Everything Dana 32 English Netherlands
1971 Monaco
Un banc, un arbre, une
rue Séverine 128 French Ireland
1972 Luxembourg Après toi Vicky Leandros 128 French
United
Kingdom
1973 Luxembourg Tu te reconnaîtras Anne-Marie David 129 French Luxembourg
YEAR WINNER SONG PERFORMER POINTS LANGUAGE HOST
This presentation is available in http://db-oriented.com/presentations
©
Oren
Nakdimon
©
Oren
Nakdimon
Find all the wins of Luxembourg
SELECT *
FROM EUROVISION_WINNERS
WHERE WINNER = 'Luxembourg';
This presentation is available in http://db-oriented.com/presentations
©
Oren
Nakdimon
©
Oren
Nakdimon
YEAR WINNER SONG HOST
1960 France Tom Pillibi United Kingdom
1961 Luxembourg Nous les amoureux France
1962 France Un premier amour Luxembourg
1963 Denmark Dansevise United Kingdom
1964 Italy Non ho l'età Denmark
1965 Luxembourg Poupée de cire, poupée de son Italy
1966 Austria Merci, Chérie Luxembourg
1967 United Kingdom Puppet on a String Austria
1968 Spain La, la, la United Kingdom
1969 Netherlands De troubadour Spain
1970 Ireland All Kinds of Everything Netherlands
1971 Monaco Un banc, un arbre, une rue Ireland
1972 Luxembourg Après toi United Kingdom
1973 Luxembourg Tu te reconnaîtras Luxembourg
1974 Sweden Waterloo United Kingdom
1975 Netherlands Ding-a-dong Sweden
1976 United Kingdom Save Your Kisses for Me Netherlands
1977 France L'oiseau et l'enfant United Kingdom
1978 Israel A-Ba-Ni-Bi France
Find all the wins of Luxembourg




Pattern
Variable
1
2
3
4
LUX
SELECT YEAR, WINNER, SONG, HOST
FROM EUROVISION_WINNERS
MATCH_RECOGNIZE (
ALL ROWS PER MATCH
PATTERN (LUX)
DEFINE LUX AS WINNER = 'Luxembourg'
)
This presentation is available in http://db-oriented.com/presentations
©
Oren
Nakdimon
©
Oren
Nakdimon
YEAR WINNER SONG HOST
1960 France Tom Pillibi United Kingdom
1961 Luxembourg Nous les amoureux France
1962 France Un premier amour Luxembourg
1963 Denmark Dansevise United Kingdom
1964 Italy Non ho l'età Denmark
1965 Luxembourg Poupée de cire, poupée de son Italy
1966 Austria Merci, Chérie Luxembourg
1967 United Kingdom Puppet on a String Austria
1968 Spain La, la, la United Kingdom
1969 Netherlands De troubadour Spain
1970 Ireland All Kinds of Everything Netherlands
1971 Monaco Un banc, un arbre, une rue Ireland
1972 Luxembourg Après toi United Kingdom
1973 Luxembourg Tu te reconnaîtras Luxembourg
1974 Sweden Waterloo United Kingdom
1975 Netherlands Ding-a-dong Sweden
1976 United Kingdom Save Your Kisses for Me Netherlands
1977 France L'oiseau et l'enfant United Kingdom
1978 Israel A-Ba-Ni-Bi France
Find 2 successive wins of Luxembourg
SELECT *
FROM EUROVISION_WINNERS
WHERE WINNER = 'Luxembourg';
This presentation is available in http://db-oriented.com/presentations
©
Oren
Nakdimon
©
Oren
Nakdimon
YEAR WINNER SONG HOST
1960 France Tom Pillibi United Kingdom
1961 Luxembourg Nous les amoureux France
1962 France Un premier amour Luxembourg
1963 Denmark Dansevise United Kingdom
1964 Italy Non ho l'età Denmark
1965 Luxembourg Poupée de cire, poupée de son Italy
1966 Austria Merci, Chérie Luxembourg
1967 United Kingdom Puppet on a String Austria
1968 Spain La, la, la United Kingdom
1969 Netherlands De troubadour Spain
1970 Ireland All Kinds of Everything Netherlands
1971 Monaco Un banc, un arbre, une rue Ireland
1972 Luxembourg Après toi United Kingdom
1973 Luxembourg Tu te reconnaîtras Luxembourg
1974 Sweden Waterloo United Kingdom
1975 Netherlands Ding-a-dong Sweden
1976 United Kingdom Save Your Kisses for Me Netherlands
1977 France L'oiseau et l'enfant United Kingdom
1978 Israel A-Ba-Ni-Bi France
Find 2 successive wins of Luxembourg




Pattern
Variable
SELECT YEAR, WINNER, SONG, HOST
FROM EUROVISION_WINNERS
MATCH_RECOGNIZE (
ORDER BY YEAR
ALL ROWS PER MATCH
PATTERN (LUX LUX)
DEFINE LUX AS WINNER = 'Luxembourg'
)
1
LUX
order by
This presentation is available in http://db-oriented.com/presentations
©
Oren
Nakdimon
©
Oren
Nakdimon
Variables Pattern
This presentation is available in http://db-oriented.com/presentations
©
Oren
Nakdimon
©
Oren
Nakdimon
YEAR WINNER SONG HOST
1960 France Tom Pillibi United Kingdom
1961 Luxembourg Nous les amoureux France
1962 France Un premier amour Luxembourg
1963 Denmark Dansevise United Kingdom
1964 Italy Non ho l'età Denmark
1965 Luxembourg Poupée de cire, poupée de son Italy
1966 Austria Merci, Chérie Luxembourg
1967 United Kingdom Puppet on a String Austria
1968 Spain La, la, la United Kingdom
1969 Netherlands De troubadour Spain
1970 Ireland All Kinds of Everything Netherlands
1971 Monaco Un banc, un arbre, une rue Ireland
1972 Luxembourg Après toi United Kingdom
1973 Luxembourg Tu te reconnaîtras Luxembourg
1974 Sweden Waterloo United Kingdom
1975 Netherlands Ding-a-dong Sweden
1976 United Kingdom Save Your Kisses for Me Netherlands
1977 France L'oiseau et l'enfant United Kingdom
1978 Israel A-Ba-Ni-Bi France
Find 2 successive wins of Luxembourg


Pattern
Variable
SELECT YEAR, WINNER, SONG, HOST
FROM EUROVISION_WINNERS
MATCH_RECOGNIZE (
ORDER BY YEAR
ALL ROWS PER MATCH
PATTERN (LUX LUX)
DEFINE LUX AS WINNER = 'Luxembourg'
)
1
LUX
order by
This presentation is available in http://db-oriented.com/presentations
©
Oren
Nakdimon
©
Oren
Nakdimon
Find 2 successive wins of Luxembourg
SELECT YEAR, WINNER, SONG, HOST
FROM EUROVISION_WINNERS
MATCH_RECOGNIZE (
ORDER BY YEAR
ALL ROWS PER MATCH
PATTERN (LUX LUX)
DEFINE LUX AS WINNER = 'Luxembourg'
)
This presentation is available in http://db-oriented.com/presentations
©
Oren
Nakdimon
©
Oren
Nakdimon
Find 2 successive wins of Luxembourg
SELECT YEAR, WINNER, SONG, HOST
FROM EUROVISION_WINNERS
MATCH_RECOGNIZE (
ORDER BY YEAR
ALL ROWS PER MATCH
PATTERN (LUX{2})
DEFINE LUX AS WINNER = 'Luxembourg'
)
This presentation is available in http://db-oriented.com/presentations
©
Oren
Nakdimon
©
Oren
Nakdimon
PATTERN Quantifiers
Pattern Number of consecutive occurrences
X 1
X{n} n
X{n,} n or more
X* 0 or more
X{n,m} between n and m
X{,m} between 0 and m
X? 0 or 1
X+ 1 or more
This presentation is available in http://db-oriented.com/presentations
©
Oren
Nakdimon
©
Oren
Nakdimon
YEAR WINNER SONG HOST
1960 France Tom Pillibi United Kingdom
1961 Luxembourg Nous les amoureux France
1962 France Un premier amour Luxembourg
1963 Denmark Dansevise United Kingdom
1964 Italy Non ho l'età Denmark
1965 Luxembourg Poupée de cire, poupée de son Italy
1966 Austria Merci, Chérie Luxembourg
1967 United Kingdom Puppet on a String Austria
1968 Spain La, la, la United Kingdom
1969 Netherlands De troubadour Spain
1970 Ireland All Kinds of Everything Netherlands
1971 Monaco Un banc, un arbre, une rue Ireland
1972 Luxembourg Après toi United Kingdom
1973 Luxembourg Tu te reconnaîtras Luxembourg
1974 Sweden Waterloo United Kingdom
1975 Netherlands Ding-a-dong Sweden
1976 United Kingdom Save Your Kisses for Me Netherlands
1977 France L'oiseau et l'enfant United Kingdom
1978 Israel A-Ba-Ni-Bi France
Find one or more successive wins of Luxembourg




Pattern
Variable
SELECT YEAR, WINNER, SONG, HOST
FROM EUROVISION_WINNERS
MATCH_RECOGNIZE (
ORDER BY YEAR
ALL ROWS PER MATCH
PATTERN (LUX+)
DEFINE LUX AS WINNER = 'Luxembourg'
)
1
2
3
LUX
order by
This presentation is available in http://db-oriented.com/presentations
©
Oren
Nakdimon
©
Oren
Nakdimon
SELECT YEAR, WINNER, SONG, HOST
FROM EUROVISION_WINNERS
MATCH_RECOGNIZE (
ORDER BY YEAR
ALL ROWS PER MATCH
PATTERN (LUX)
DEFINE LUX AS WINNER = 'Luxembourg'
)
SELECT YEAR, WINNER, SONG, HOST
FROM EUROVISION_WINNERS
MATCH_RECOGNIZE (
ORDER BY YEAR
ALL ROWS PER MATCH
PATTERN (LUX+)
DEFINE LUX AS WINNER = 'Luxembourg'
)
This presentation is available in http://db-oriented.com/presentations
©
Oren
Nakdimon
©
Oren
Nakdimon
A match is
a consecutive sequence
of
(zero, one, or more)
records,
that matches a
specific pattern
This presentation is available in http://db-oriented.com/presentations
©
Oren
Nakdimon
©
Oren
Nakdimon
SELECT YEAR, WINNER, SONG, HOST
FROM EUROVISION_WINNERS
MATCH_RECOGNIZE (
ORDER BY YEAR
MEASURES
MATCH_NUMBER() AS MATCH#
ALL ROWS PER MATCH
PATTERN (LUX)
DEFINE LUX AS WINNER = 'Luxembourg'
)
SELECT YEAR, WINNER, SONG, HOST
FROM EUROVISION_WINNERS
MATCH_RECOGNIZE (
ORDER BY YEAR
MEASURES
MATCH_NUMBER() AS MATCH#
ALL ROWS PER MATCH
PATTERN (LUX+)
DEFINE LUX AS WINNER = 'Luxembourg'
)
This presentation is available in http://db-oriented.com/presentations
©
Oren
Nakdimon
©
Oren
Nakdimon
SELECT MATCH#, YEAR, WINNER, SONG, HOST
FROM EUROVISION_WINNERS
MATCH_RECOGNIZE (
ORDER BY YEAR
MEASURES
MATCH_NUMBER() AS MATCH#
ALL ROWS PER MATCH
PATTERN (LUX)
DEFINE LUX AS WINNER = 'Luxembourg'
)
SELECT MATCH#, YEAR, WINNER, SONG, HOST
FROM EUROVISION_WINNERS
MATCH_RECOGNIZE (
ORDER BY YEAR
MEASURES
MATCH_NUMBER() AS MATCH#
ALL ROWS PER MATCH
PATTERN (LUX+)
DEFINE LUX AS WINNER = 'Luxembourg'
)
This presentation is available in http://db-oriented.com/presentations
©
Oren
Nakdimon
©
Oren
Nakdimon
MATCH_RECOGNIZE
This presentation is available in http://db-oriented.com/presentations
©
Oren
Nakdimon
©
Oren
Nakdimon
Input and Output
SELECT * FROM
(SELECT YEAR, WINNER, SONG, PERFORMER, HOST
FROM EUROVISION_WINNERS
WHERE YEAR BETWEEN 1990 AND 2000)
MATCH_RECOGNIZE (
ORDER BY YEAR
MEASURES
MATCH_NUMBER() AS MATCH#
ALL ROWS PER MATCH
PATTERN (I L UK?)
DEFINE I AS WINNER LIKE 'I%',
LN AS LENGTH(SONG)>=18,
UK AS HOST='United Kingdom'
);
This presentation is available in http://db-oriented.com/presentations
©
Oren
Nakdimon
©
Oren
Nakdimon
Input and Output
SELECT * FROM
(SELECT YEAR, WINNER, SONG, PERFORMER, HOST
FROM EUROVISION_WINNERS
WHERE YEAR BETWEEN 1990 AND 2000)
MATCH_RECOGNIZE (
ORDER BY YEAR
MEASURES
MATCH_NUMBER() AS MATCH#
ALL ROWS PER MATCH
PATTERN (I L UK?)
DEFINE I AS WINNER LIKE 'I%',
LN AS LENGTH(SONG)>=18,
UK AS HOST='United Kingdom'
);
This presentation is available in http://db-oriented.com/presentations
©
Oren
Nakdimon
©
Oren
Nakdimon
SELECT * FROM
(SELECT YEAR, WINNER, SONG, HOST
FROM EUROVISION_WINNERS
WHERE YEAR BETWEEN 1990 AND 2000)
MATCH_RECOGNIZE (
ORDER BY YEAR
MEASURES
MATCH_NUMBER() AS MATCH#
ALL ROWS PER MATCH
PATTERN (I L UK?)
DEFINE I AS WINNER LIKE 'I%',
LN AS LENGTH(SONG)>=18,
UK AS HOST='United Kingdom'
);
Input and Output
This presentation is available in http://db-oriented.com/presentations
©
Oren
Nakdimon
©
Oren
Nakdimon
SELECT * FROM
(SELECT YEAR, WINNER, SONG, HOST
FROM EUROVISION_WINNERS
WHERE YEAR BETWEEN 1990 AND 2000)
MATCH_RECOGNIZE (
ORDER BY YEAR
MEASURES
MATCH_NUMBER() AS MATCH#
ALL ROWS PER MATCH
PATTERN (I L UK?)
DEFINE I AS WINNER LIKE 'I%',
LN AS LENGTH(SONG)>=18,
UK AS HOST='United Kingdom'
);
Input and Output
YEAR WINNER SONG HOST
1990 Italy Insieme: 1992 Yugoslavia
1991 Sweden Fångad av en stormvind Italy
1992 Ireland Why Me? Sweden
1993 Ireland In Your Eyes Ireland
1994 Ireland Rock 'n' Roll Kids Ireland
1995 Norway Nocturne Ireland
1996 Ireland The Voice Norway
1997 United Kingdom Love Shine a Light Ireland
1998 Israel Diva United Kingdom
1999 Sweden Take Me to Your Heaven Israel
2000 Denmark Fly on the Wings of Love Sweden
This presentation is available in http://db-oriented.com/presentations
©
Oren
Nakdimon
©
Oren
Nakdimon
Multiple Pattern Variables
YEAR WINNER SONG HOST
1990 Italy Insieme: 1992 Yugoslavia
1991 Sweden Fångad av en stormvind Italy
1992 Ireland Why Me? Sweden
1993 Ireland In Your Eyes Ireland
1994 Ireland Rock 'n' Roll Kids Ireland
1995 Norway Nocturne Ireland
1996 Ireland The Voice Norway
1997 United Kingdom Love Shine a Light Ireland
1998 Israel Diva United Kingdom
1999 Sweden Take Me to Your Heaven Israel
2000 Denmark Fly on the Wings of Love Sweden
SELECT * FROM
(SELECT YEAR, WINNER, SONG, HOST
FROM EUROVISION_WINNERS
WHERE YEAR BETWEEN 1990 AND 2000)
MATCH_RECOGNIZE (
ORDER BY YEAR
MEASURES
MATCH_NUMBER() AS MATCH#
ALL ROWS PER MATCH
PATTERN (I LN UK?)
DEFINE I AS WINNER LIKE 'I%',
LN AS LENGTH(SONG)>=18,
UK AS HOST='United Kingdom'
);
order by
This presentation is available in http://db-oriented.com/presentations
©
Oren
Nakdimon
©
Oren
Nakdimon
SELECT * FROM
(SELECT YEAR, WINNER, SONG, PERFORMER, HOST
FROM EUROVISION_WINNERS
WHERE YEAR BETWEEN 1990 AND 2000)
MATCH_RECOGNIZE (
ORDER BY YEAR
MEASURES
MATCH_NUMBER() AS MATCH#
ALL ROWS PER MATCH
PATTERN (I LN UK?)
DEFINE I AS WINNER LIKE 'I%',
LN AS LENGTH(SONG)>=18,
UK AS HOST='United Kingdom'
);
Multiple Pattern Variables
YEAR WINNER SONG HOST
1990 Italy Insieme: 1992 Yugoslavia
1991 Sweden Fångad av en stormvind Italy
1992 Ireland Why Me? Sweden
1993 Ireland In Your Eyes Ireland
1994 Ireland Rock 'n' Roll Kids Ireland
1995 Norway Nocturne Ireland
1996 Ireland The Voice Norway
1997 United Kingdom Love Shine a Light Ireland
1998 Israel Diva United Kingdom
1999 Sweden Take Me to Your Heaven Israel
2000 Denmark Fly on the Wings of Love Sweden
order by
This presentation is available in http://db-oriented.com/presentations
©
Oren
Nakdimon
©
Oren
Nakdimon
SELECT * FROM
(SELECT YEAR, WINNER, SONG, PERFORMER, HOST
FROM EUROVISION_WINNERS
WHERE YEAR BETWEEN 1990 AND 2000)
MATCH_RECOGNIZE (
ORDER BY YEAR
MEASURES
MATCH_NUMBER() AS MATCH#
ALL ROWS PER MATCH
PATTERN (I LN UK?)
DEFINE I AS WINNER LIKE 'I%',
LN AS LENGTH(SONG)>=18,
UK AS HOST='United Kingdom'
);
Multiple Pattern Variables
YEAR WINNER SONG HOST
1990 Italy Insieme: 1992 Yugoslavia
1991 Sweden Fångad av en stormvind Italy
1992 Ireland Why Me? Sweden
1993 Ireland In Your Eyes Ireland
1994 Ireland Rock 'n' Roll Kids Ireland
1995 Norway Nocturne Ireland
1996 Ireland The Voice Norway
1997 United Kingdom Love Shine a Light Ireland
1998 Israel Diva United Kingdom
1999 Sweden Take Me to Your Heaven Israel
2000 Denmark Fly on the Wings of Love Sweden
I
?
?
?
?
?
?
Pattern
Variables
order by
This presentation is available in http://db-oriented.com/presentations
©
Oren
Nakdimon
©
Oren
Nakdimon
SELECT * FROM
(SELECT YEAR, WINNER, SONG, PERFORMER, HOST
FROM EUROVISION_WINNERS
WHERE YEAR BETWEEN 1990 AND 2000)
MATCH_RECOGNIZE (
ORDER BY YEAR
MEASURES
MATCH_NUMBER() AS MATCH#
ALL ROWS PER MATCH
PATTERN (I LN UK?)
DEFINE I AS WINNER LIKE 'I%',
LN AS LENGTH(SONG)>=18,
UK AS HOST='United Kingdom'
);
Multiple Pattern Variables
YEAR WINNER SONG HOST
1990 Italy Insieme: 1992 Yugoslavia
1991 Sweden Fångad av en stormvind Italy
1992 Ireland Why Me? Sweden
1993 Ireland In Your Eyes Ireland
1994 Ireland Rock 'n' Roll Kids Ireland
1995 Norway Nocturne Ireland
1996 Ireland The Voice Norway
1997 United Kingdom Love Shine a Light Ireland
1998 Israel Diva United Kingdom
1999 Sweden Take Me to Your Heaven Israel
2000 Denmark Fly on the Wings of Love Sweden
I
?
?
?
?
?
?
LN
?
?
?
?
?
Pattern
Variables
order by
This presentation is available in http://db-oriented.com/presentations
©
Oren
Nakdimon
©
Oren
Nakdimon
SELECT * FROM
(SELECT YEAR, WINNER, SONG, PERFORMER, HOST
FROM EUROVISION_WINNERS
WHERE YEAR BETWEEN 1990 AND 2000)
MATCH_RECOGNIZE (
ORDER BY YEAR
MEASURES
MATCH_NUMBER() AS MATCH#
ALL ROWS PER MATCH
PATTERN (I LN UK?)
DEFINE I AS WINNER LIKE 'I%',
LN AS LENGTH(SONG)>=18,
UK AS HOST='United Kingdom'
);
Multiple Pattern Variables
YEAR WINNER SONG HOST
1990 Italy Insieme: 1992 Yugoslavia
1991 Sweden Fångad av en stormvind Italy
1992 Ireland Why Me? Sweden
1993 Ireland In Your Eyes Ireland
1994 Ireland Rock 'n' Roll Kids Ireland
1995 Norway Nocturne Ireland
1996 Ireland The Voice Norway
1997 United Kingdom Love Shine a Light Ireland
1998 Israel Diva United Kingdom
1999 Sweden Take Me to Your Heaven Israel
2000 Denmark Fly on the Wings of Love Sweden
I
?
?
?
?
?
?
LN
?
?
?
?
?
UK
?
Pattern
Variables
order by
This presentation is available in http://db-oriented.com/presentations
©
Oren
Nakdimon
©
Oren
Nakdimon
UK
LN
I
SELECT * FROM
(SELECT YEAR, WINNER, SONG, PERFORMER, HOST
FROM EUROVISION_WINNERS
WHERE YEAR BETWEEN 1990 AND 2000)
MATCH_RECOGNIZE (
ORDER BY YEAR
MEASURES
MATCH_NUMBER() AS MATCH#
ALL ROWS PER MATCH
PATTERN (I LN UK?)
DEFINE I AS WINNER LIKE 'I%',
LN AS LENGTH(SONG)>=18,
UK AS HOST='United Kingdom'
);




Multiple Pattern Variables
1
2
3
YEAR WINNER SONG HOST
1990 Italy Insieme: 1992 Yugoslavia
1991 Sweden Fångad av en stormvind Italy
1992 Ireland Why Me? Sweden
1993 Ireland In Your Eyes Ireland
1994 Ireland Rock 'n' Roll Kids Ireland
1995 Norway Nocturne Ireland
1996 Ireland The Voice Norway
1997 United Kingdom Love Shine a Light Ireland
1998 Israel Diva United Kingdom
1999 Sweden Take Me to Your Heaven Israel
2000 Denmark Fly on the Wings of Love Sweden
Pattern
Variables
order by




This presentation is available in http://db-oriented.com/presentations
©
Oren
Nakdimon
©
Oren
Nakdimon
UK
LN
I




Multiple Pattern Variables
1
2
3
YEAR WINNER SONG HOST
1990 Italy Insieme: 1992 Yugoslavia
1991 Sweden Fångad av en stormvind Italy
1992 Ireland Why Me? Sweden
1993 Ireland In Your Eyes Ireland
1994 Ireland Rock 'n' Roll Kids Ireland
1995 Norway Nocturne Ireland
1996 Ireland The Voice Norway
1997 United Kingdom Love Shine a Light Ireland
1998 Israel Diva United Kingdom
1999 Sweden Take Me to Your Heaven Israel
2000 Denmark Fly on the Wings of Love Sweden
Pattern
Variables
order by




SELECT * FROM
(SELECT YEAR, WINNER, SONG, HOST
FROM EUROVISION_WINNERS
WHERE YEAR BETWEEN 1990 AND 2000)
MATCH_RECOGNIZE (
ORDER BY YEAR
MEASURES
MATCH_NUMBER() AS MATCH#
ALL ROWS PER MATCH
PATTERN (I LN UK?)
DEFINE I AS WINNER LIKE 'I%',
LN AS LENGTH(SONG)>=18,
UK AS HOST='United Kingdom'
);
This presentation is available in http://db-oriented.com/presentations
©
Oren
Nakdimon
©
Oren
Nakdimon
Find two or more successive wins of the same country


YEAR WINNER SONG HOST
1977 France L'oiseau et l'enfant United Kingdom
1978 Israel A-Ba-Ni-Bi France
1979 Israel Hallelujah Israel
1980 Ireland What's Another Year Netherlands
1981 United Kingdom Making Your Mind Up Ireland
1982 Germany Ein bißchen Frieden United Kingdom
1983 Luxembourg Si la vie est cadeau Germany
1984 Sweden Diggi-Loo Diggi-Ley Luxembourg
1985 Norway La det swinge Sweden
1986 Belgium J'aime la vie Norway
1987 Ireland Hold Me Now Belgium
1988 Switzerland Ne partez pas sans moi Ireland
1989 Yugoslavia Rock Me Switzerland
1990 Italy Insieme: 1992 Yugoslavia
1991 Sweden Fångad av en stormvind Italy
1992 Ireland Why Me? Sweden
1993 Ireland In Your Eyes Ireland
1994 Ireland Rock 'n' Roll Kids Ireland
1995 Norway Nocturne Ireland
X SAME
SELECT MATCH#, YEAR, WINNER, SONG, HOST
FROM EUROVISION_WINNERS
MATCH_RECOGNIZE (
ORDER BY YEAR
MEASURES
MATCH_NUMBER() AS MATCH#
ALL ROWS PER MATCH
PATTERN (X SAME+)
DEFINE SAME AS WINNER = PREV(WINNER)
);















Implicit Pattern
Variable
PREV
NEXT
This presentation is available in http://db-oriented.com/presentations
©
Oren
Nakdimon
©
Oren
Nakdimon
Find returning winners after a break
YEAR WINNER SONG POINTS
1971 Monaco Un banc, un arbre, une rue 128
1972 Luxembourg Après toi 128
1973 Luxembourg Tu te reconnaîtras 129
1974 Sweden Waterloo 24
1975 Netherlands Ding-a-dong 152
1976 United Kingdom Save Your Kisses for Me 164
1977 France L'oiseau et l'enfant 136
1978 Israel A-Ba-Ni-Bi 157
1979 Israel Hallelujah 125
1980 Ireland What's Another Year 143
1981 United Kingdom Making Your Mind Up 136
1982 Germany Ein bißchen Frieden 161
1983 Luxembourg Si la vie est cadeau 142
1984 Sweden Diggi-Loo Diggi-Ley 145
1985 Norway La det swinge 123
1986 Belgium J'aime la vie 176
1987 Ireland Hold Me Now 172
1988 Switzerland Ne partez pas sans moi 137
1989 Yugoslavia Rock Me 137
1990 Italy Insieme: 1992 149
1991 Sweden Fångad av en stormvind 146
This presentation is available in http://db-oriented.com/presentations
©
Oren
Nakdimon
©
Oren
Nakdimon
Find returning winners after a break
YEAR WINNER SONG POINTS
1971 Monaco Un banc, un arbre, une rue 128
1972 Luxembourg Après toi 128
1973 Luxembourg Tu te reconnaîtras 129
1974 Sweden Waterloo 24
1975 Netherlands Ding-a-dong 152
1976 United Kingdom Save Your Kisses for Me 164
1977 France L'oiseau et l'enfant 136
1978 Israel A-Ba-Ni-Bi 157
1979 Israel Hallelujah 125
1980 Ireland What's Another Year 143
1981 United Kingdom Making Your Mind Up 136
1982 Germany Ein bißchen Frieden 161
1983 Luxembourg Si la vie est cadeau 142
1984 Sweden Diggi-Loo Diggi-Ley 145
1985 Norway La det swinge 123
1986 Belgium J'aime la vie 176
1987 Ireland Hold Me Now 172
1988 Switzerland Ne partez pas sans moi 137
1989 Yugoslavia Rock Me 137
1990 Italy Insieme: 1992 149
1991 Sweden Fångad av en stormvind 146
SELECT MATCH#, YEAR, WINNER, SONG, POINTS, CLS
FROM (SELECT * FROM EUROVISION_WINNERS
WHERE YEAR BETWEEN 1971 AND 1991)
MATCH_RECOGNIZE (
ORDER BY YEAR
MEASURES
MATCH_NUMBER() MATCH#,
CLASSIFIER() CLS
ALL ROWS PER MATCH
AFTER MATCH SKIP PAST LAST ROW
PATTERN (A SAME* DIFF+ LIKE_FIRST+)
DEFINE
SAME AS WINNER = PREV(WINNER),
DIFF AS WINNER != A.WINNER,
LIKE_FIRST AS WINNER = A.WINNER
)
ORDER BY YEAR;
This presentation is available in http://db-oriented.com/presentations
©
Oren
Nakdimon
©
Oren
Nakdimon
Find returning winners after a break
YEAR WINNER SONG POINTS
1971 Monaco Un banc, un arbre, une rue 128
1972 Luxembourg Après toi 128
1973 Luxembourg Tu te reconnaîtras 129
1974 Sweden Waterloo 24
1975 Netherlands Ding-a-dong 152
1976 United Kingdom Save Your Kisses for Me 164
1977 France L'oiseau et l'enfant 136
1978 Israel A-Ba-Ni-Bi 157
1979 Israel Hallelujah 125
1980 Ireland What's Another Year 143
1981 United Kingdom Making Your Mind Up 136
1982 Germany Ein bißchen Frieden 161
1983 Luxembourg Si la vie est cadeau 142
1984 Sweden Diggi-Loo Diggi-Ley 145
1985 Norway La det swinge 123
1986 Belgium J'aime la vie 176
1987 Ireland Hold Me Now 172
1988 Switzerland Ne partez pas sans moi 137
1989 Yugoslavia Rock Me 137
1990 Italy Insieme: 1992 149
1991 Sweden Fångad av en stormvind 146
SELECT MATCH#, YEAR, WINNER, SONG, POINTS, CLS
FROM (SELECT * FROM EUROVISION_WINNERS
WHERE YEAR BETWEEN 1971 AND 1991)
MATCH_RECOGNIZE (
ORDER BY YEAR
MEASURES
MATCH_NUMBER() MATCH#,
CLASSIFIER() CLS
ALL ROWS PER MATCH
AFTER MATCH SKIP PAST LAST ROW
PATTERN (A SAME* DIFF+ LIKE_FIRST+)
DEFINE
SAME AS WINNER = PREV(WINNER),
DIFF AS WINNER != A.WINNER,
LIKE_FIRST AS WINNER = A.WINNER
)
ORDER BY YEAR;
This presentation is available in http://db-oriented.com/presentations
©
Oren
Nakdimon
©
Oren
Nakdimon
Find returning winners after a break
YEAR WINNER SONG POINTS
1971 Monaco Un banc, un arbre, une rue 128
1972 Luxembourg Après toi 128
1973 Luxembourg Tu te reconnaîtras 129
1974 Sweden Waterloo 24
1975 Netherlands Ding-a-dong 152
1976 United Kingdom Save Your Kisses for Me 164
1977 France L'oiseau et l'enfant 136
1978 Israel A-Ba-Ni-Bi 157
1979 Israel Hallelujah 125
1980 Ireland What's Another Year 143
1981 United Kingdom Making Your Mind Up 136
1982 Germany Ein bißchen Frieden 161
1983 Luxembourg Si la vie est cadeau 142
1984 Sweden Diggi-Loo Diggi-Ley 145
1985 Norway La det swinge 123
1986 Belgium J'aime la vie 176
1987 Ireland Hold Me Now 172
1988 Switzerland Ne partez pas sans moi 137
1989 Yugoslavia Rock Me 137
1990 Italy Insieme: 1992 149
1991 Sweden Fångad av en stormvind 146
SELECT MATCH#, YEAR, WINNER, SONG, POINTS, CLS
FROM (SELECT * FROM EUROVISION_WINNERS
WHERE YEAR BETWEEN 1971 AND 1991)
MATCH_RECOGNIZE (
ORDER BY YEAR
MEASURES
MATCH_NUMBER() MATCH#,
CLASSIFIER() CLS
ALL ROWS PER MATCH
AFTER MATCH SKIP PAST LAST ROW
PATTERN (A SAME* DIFF+ LIKE_FIRST+)
DEFINE
SAME AS WINNER = PREV(WINNER),
DIFF AS WINNER != A.WINNER,
LIKE_FIRST AS WINNER = A.WINNER
)
ORDER BY YEAR;
This presentation is available in http://db-oriented.com/presentations
©
Oren
Nakdimon
©
Oren
Nakdimon
Find returning winners after a break
YEAR WINNER SONG POINTS
1971 Monaco Un banc, un arbre, une rue 128
1972 Luxembourg Après toi 128
1973 Luxembourg Tu te reconnaîtras 129
1974 Sweden Waterloo 24
1975 Netherlands Ding-a-dong 152
1976 United Kingdom Save Your Kisses for Me 164
1977 France L'oiseau et l'enfant 136
1978 Israel A-Ba-Ni-Bi 157
1979 Israel Hallelujah 125
1980 Ireland What's Another Year 143
1981 United Kingdom Making Your Mind Up 136
1982 Germany Ein bißchen Frieden 161
1983 Luxembourg Si la vie est cadeau 142
1984 Sweden Diggi-Loo Diggi-Ley 145
1985 Norway La det swinge 123
1986 Belgium J'aime la vie 176
1987 Ireland Hold Me Now 172
1988 Switzerland Ne partez pas sans moi 137
1989 Yugoslavia Rock Me 137
1990 Italy Insieme: 1992 149
1991 Sweden Fångad av en stormvind 146
SELECT MATCH#, YEAR, WINNER, SONG, POINTS, CLS
FROM (SELECT * FROM EUROVISION_WINNERS
WHERE YEAR BETWEEN 1971 AND 1991)
MATCH_RECOGNIZE (
ORDER BY YEAR
MEASURES
MATCH_NUMBER() MATCH#,
CLASSIFIER() CLS
ALL ROWS PER MATCH
AFTER MATCH SKIP PAST LAST ROW
PATTERN (A SAME* DIFF+ LIKE_FIRST+)
DEFINE
SAME AS WINNER = PREV(WINNER),
DIFF AS WINNER != A.WINNER,
LIKE_FIRST AS WINNER = A.WINNER
)
ORDER BY YEAR;
This presentation is available in http://db-oriented.com/presentations
©
Oren
Nakdimon
©
Oren
Nakdimon
Find returning winners after a break
YEAR WINNER SONG POINTS
1971 Monaco Un banc, un arbre, une rue 128
1972 Luxembourg Après toi 128
1973 Luxembourg Tu te reconnaîtras 129
1974 Sweden Waterloo 24
1975 Netherlands Ding-a-dong 152
1976 United Kingdom Save Your Kisses for Me 164
1977 France L'oiseau et l'enfant 136
1978 Israel A-Ba-Ni-Bi 157
1979 Israel Hallelujah 125
1980 Ireland What's Another Year 143
1981 United Kingdom Making Your Mind Up 136
1982 Germany Ein bißchen Frieden 161
1983 Luxembourg Si la vie est cadeau 142
1984 Sweden Diggi-Loo Diggi-Ley 145
1985 Norway La det swinge 123
1986 Belgium J'aime la vie 176
1987 Ireland Hold Me Now 172
1988 Switzerland Ne partez pas sans moi 137
1989 Yugoslavia Rock Me 137
1990 Italy Insieme: 1992 149
1991 Sweden Fångad av en stormvind 146
SELECT MATCH#, YEAR, WINNER, SONG, POINTS, CLS
FROM (SELECT * FROM EUROVISION_WINNERS
WHERE YEAR BETWEEN 1971 AND 1991)
MATCH_RECOGNIZE (
ORDER BY YEAR
MEASURES
MATCH_NUMBER() MATCH#,
CLASSIFIER() CLS
ALL ROWS PER MATCH
AFTER MATCH SKIP PAST LAST ROW
PATTERN (A SAME* DIFF+ LIKE_FIRST+)
DEFINE
SAME AS WINNER = PREV(WINNER),
DIFF AS WINNER != A.WINNER,
LIKE_FIRST AS WINNER = A.WINNER
)
ORDER BY YEAR;
This presentation is available in http://db-oriented.com/presentations
©
Oren
Nakdimon
©
Oren
Nakdimon
Find returning winners after a break
YEAR WINNER SONG POINTS
1971 Monaco Un banc, un arbre, une rue 128
1972 Luxembourg Après toi 128
1973 Luxembourg Tu te reconnaîtras 129
1974 Sweden Waterloo 24
1975 Netherlands Ding-a-dong 152
1976 United Kingdom Save Your Kisses for Me 164
1977 France L'oiseau et l'enfant 136
1978 Israel A-Ba-Ni-Bi 157
1979 Israel Hallelujah 125
1980 Ireland What's Another Year 143
1981 United Kingdom Making Your Mind Up 136
1982 Germany Ein bißchen Frieden 161
1983 Luxembourg Si la vie est cadeau 142
1984 Sweden Diggi-Loo Diggi-Ley 145
1985 Norway La det swinge 123
1986 Belgium J'aime la vie 176
1987 Ireland Hold Me Now 172
1988 Switzerland Ne partez pas sans moi 137
1989 Yugoslavia Rock Me 137
1990 Italy Insieme: 1992 149
1991 Sweden Fångad av en stormvind 146
SELECT MATCH#, YEAR, WINNER, SONG, POINTS, CLS
FROM (SELECT * FROM EUROVISION_WINNERS
WHERE YEAR BETWEEN 1971 AND 1991)
MATCH_RECOGNIZE (
ORDER BY YEAR
MEASURES
MATCH_NUMBER() MATCH#,
CLASSIFIER() CLS
ALL ROWS PER MATCH
AFTER MATCH SKIP PAST LAST ROW
PATTERN (A SAME* DIFF+ LIKE_FIRST+)
DEFINE
SAME AS WINNER = PREV(WINNER),
DIFF AS WINNER != A.WINNER,
LIKE_FIRST AS WINNER = A.WINNER
)
ORDER BY YEAR;
This presentation is available in http://db-oriented.com/presentations
©
Oren
Nakdimon
©
Oren
Nakdimon
Find returning winners after a break
YEAR WINNER SONG POINTS
1971 Monaco Un banc, un arbre, une rue 128
1972 Luxembourg Après toi 128
1973 Luxembourg Tu te reconnaîtras 129
1974 Sweden Waterloo 24
1975 Netherlands Ding-a-dong 152
1976 United Kingdom Save Your Kisses for Me 164
1977 France L'oiseau et l'enfant 136
1978 Israel A-Ba-Ni-Bi 157
1979 Israel Hallelujah 125
1980 Ireland What's Another Year 143
1981 United Kingdom Making Your Mind Up 136
1982 Germany Ein bißchen Frieden 161
1983 Luxembourg Si la vie est cadeau 142
1984 Sweden Diggi-Loo Diggi-Ley 145
1985 Norway La det swinge 123
1986 Belgium J'aime la vie 176
1987 Ireland Hold Me Now 172
1988 Switzerland Ne partez pas sans moi 137
1989 Yugoslavia Rock Me 137
1990 Italy Insieme: 1992 149
1991 Sweden Fångad av en stormvind 146
SELECT MATCH#, YEAR, WINNER, SONG, POINTS, CLS
FROM (SELECT * FROM EUROVISION_WINNERS
WHERE YEAR BETWEEN 1971 AND 1991)
MATCH_RECOGNIZE (
ORDER BY YEAR
MEASURES
MATCH_NUMBER() MATCH#,
CLASSIFIER() CLS
ALL ROWS PER MATCH
AFTER MATCH SKIP PAST LAST ROW
PATTERN (A SAME* DIFF+ LIKE_FIRST+)
DEFINE
SAME AS WINNER = PREV(WINNER),
DIFF AS WINNER != A.WINNER,
LIKE_FIRST AS WINNER = A.WINNER
)
ORDER BY YEAR;
This presentation is available in http://db-oriented.com/presentations
©
Oren
Nakdimon
©
Oren
Nakdimon
Find returning winners after a break
SELECT MATCH#, YEAR, WINNER, SONG, POINTS, CLS
FROM (SELECT * FROM EUROVISION_WINNERS
WHERE YEAR BETWEEN 1971 AND 1991)
MATCH_RECOGNIZE (
ORDER BY YEAR
MEASURES
MATCH_NUMBER() MATCH#,
CLASSIFIER() CLS
ALL ROWS PER MATCH
AFTER MATCH SKIP PAST LAST ROW
PATTERN (A SAME* DIFF+ LIKE_FIRST+)
DEFINE
SAME AS WINNER = PREV(WINNER),
DIFF AS WINNER != A.WINNER,
LIKE_FIRST AS WINNER = A.WINNER
)
ORDER BY YEAR;
This presentation is available in http://db-oriented.com/presentations
©
Oren
Nakdimon
©
Oren
Nakdimon
SELECT MATCH#, YEAR, WINNER, SONG, POINTS, CLS
FROM (SELECT * FROM EUROVISION_WINNERS
WHERE YEAR BETWEEN 1971 AND 1991)
MATCH_RECOGNIZE (
ORDER BY YEAR
MEASURES
MATCH_NUMBER() MATCH#,
CLASSIFIER() CLS
ALL ROWS PER MATCH
AFTER MATCH SKIP PAST LAST ROW
PATTERN (A SAME* DIFF+ LIKE_FIRST+)
DEFINE
SAME AS WINNER = PREV(WINNER),
DIFF AS WINNER != A.WINNER,
LIKE_FIRST AS WINNER = A.WINNER
)
ORDER BY YEAR;
This presentation is available in http://db-oriented.com/presentations
©
Oren
Nakdimon
©
Oren
Nakdimon
SELECT MATCH#, YEAR, WINNER, SONG, POINTS, VAR
FROM (SELECT * FROM EUROVISION_WINNERS
WHERE YEAR BETWEEN 1971 AND 1991)
MATCH_RECOGNIZE (
ORDER BY YEAR
MEASURES
MATCH_NUMBER() MATCH#,
CLASSIFIER() VAR
ALL ROWS PER MATCH
AFTER MATCH SKIP PAST LAST ROW
PATTERN (A SAME* DIFF+ LIKE_FIRST+)
DEFINE
SAME AS WINNER = PREV(WINNER),
DIFF AS WINNER != A.WINNER,
LIKE_FIRST AS WINNER = A.WINNER
)
ORDER BY YEAR;
This presentation is available in http://db-oriented.com/presentations
©
Oren
Nakdimon
©
Oren
Nakdimon
SELECT MATCH#, YEAR, WINNER, SONG, POINTS, VAR
FROM (SELECT * FROM EUROVISION_WINNERS
WHERE YEAR BETWEEN 1971 AND 1991)
MATCH_RECOGNIZE (
ORDER BY YEAR
MEASURES
MATCH_NUMBER() MATCH#,
CLASSIFIER() VAR
ALL ROWS PER MATCH WITH UNMATCHED ROWS
AFTER MATCH SKIP PAST LAST ROW
PATTERN (A SAME* DIFF+ LIKE_FIRST+)
DEFINE
SAME AS WINNER = PREV(WINNER),
DIFF AS WINNER != A.WINNER,
LIKE_FIRST AS WINNER = A.WINNER
)
ORDER BY YEAR;
This presentation is available in http://db-oriented.com/presentations
©
Oren
Nakdimon
©
Oren
Nakdimon
SELECT MATCH#, YEAR, WINNER, SONG, POINTS, VAR
FROM (SELECT * FROM EUROVISION_WINNERS
WHERE YEAR BETWEEN 1971 AND 1991)
MATCH_RECOGNIZE (
ORDER BY YEAR
MEASURES
MATCH_NUMBER() MATCH#,
CLASSIFIER() VAR
ALL ROWS PER MATCH WITH UNMATCHED ROWS
AFTER MATCH SKIP PAST LAST ROW
PATTERN (A SAME* DIFF+ LIKE_FIRST+)
DEFINE
SAME AS WINNER = PREV(WINNER),
DIFF AS WINNER != A.WINNER,
LIKE_FIRST AS WINNER = A.WINNER
)
ORDER BY YEAR;
PAST LAST ROW (the default)
TO NEXT ROW
TO FIRST var
TO [LAST] var
This presentation is available in http://db-oriented.com/presentations
©
Oren
Nakdimon
©
Oren
Nakdimon
SELECT MATCH#, YEAR, WINNER, SONG, POINTS, VAR
FROM (SELECT * FROM EUROVISION_WINNERS
WHERE YEAR BETWEEN 1971 AND 1991)
MATCH_RECOGNIZE (
ORDER BY YEAR
MEASURES
MATCH_NUMBER() MATCH#,
CLASSIFIER() VAR
ALL ROWS PER MATCH WITH UNMATCHED ROWS
AFTER MATCH SKIP TO FIRST DIFF
PATTERN (A SAME* DIFF+ LIKE_FIRST+)
DEFINE
SAME AS WINNER = PREV(WINNER),
DIFF AS WINNER != A.WINNER,
LIKE_FIRST AS WINNER = A.WINNER
)
ORDER BY MATCH#, YEAR;
This presentation is available in http://db-oriented.com/presentations
©
Oren
Nakdimon
©
Oren
Nakdimon
SELECT MATCH#, YEAR, WINNER, SONG, POINTS, VAR
FROM (SELECT * FROM EUROVISION_WINNERS
WHERE YEAR BETWEEN 1971 AND 1991)
MATCH_RECOGNIZE (
ORDER BY YEAR
MEASURES
MATCH_NUMBER() MATCH#,
CLASSIFIER() VAR
ALL ROWS PER MATCH WITH UNMATCHED ROWS
AFTER MATCH SKIP TO FIRST DIFF
PATTERN (A SAME* DIFF+ LIKE_FIRST+)
DEFINE
SAME AS WINNER = PREV(WINNER),
DIFF AS WINNER != A.WINNER,
LIKE_FIRST AS WINNER = A.WINNER
)
ORDER BY MATCH#, YEAR;
FROM_YEAR
TO_YEAR
9
NON_WINNING_YEARS
WINNER
This presentation is available in http://db-oriented.com/presentations
©
Oren
Nakdimon
©
Oren
Nakdimon
FROM_YEAR
TO_YEAR
9
WINNER
SELECT MATCH#, WINNER, FROM_YEAR, TO_YEAR,
NON_WINNER_YEARS
FROM (SELECT * FROM EUROVISION_WINNERS
WHERE YEAR BETWEEN 1971 AND 1991)
MATCH_RECOGNIZE (
ORDER BY YEAR
MEASURES
MATCH_NUMBER() MATCH#,
A.WINNER WINNER,
FIRST(YEAR) FROM_YEAR,
LAST(YEAR) TO_YEAR,
COUNT(DIFF.*) NON_WINNER_YEARS
ONE ROW PER MATCH
AFTER MATCH SKIP TO FIRST DIFF
PATTERN (A SAME* DIFF+ LIKE_FIRST+)
DEFINE
SAME AS WINNER = PREV(WINNER),
DIFF AS WINNER != A.WINNER,
LIKE_FIRST AS WINNER = A.WINNER
)
ORDER BY MATCH#;
NON_WINNING_YEARS
This presentation is available in http://db-oriented.com/presentations
©
Oren
Nakdimon
©
Oren
Nakdimon
FROM_YEAR
TO_YEAR
9
WINNER
SELECT MATCH#, WINNER, FROM_YEAR, TO_YEAR,
NON_WINNER_YEARS
FROM (SELECT * FROM EUROVISION_WINNERS
WHERE YEAR BETWEEN 1971 AND 1991)
MATCH_RECOGNIZE (
ORDER BY YEAR
MEASURES
MATCH_NUMBER() MATCH#,
A.WINNER WINNER,
FIRST(YEAR) FROM_YEAR,
LAST(YEAR) TO_YEAR,
COUNT(DIFF.*) NON_WINNER_YEARS
ONE ROW PER MATCH
AFTER MATCH SKIP TO FIRST DIFF
PATTERN (A SAME* DIFF+ LIKE_FIRST+)
DEFINE
SAME AS WINNER = PREV(WINNER),
DIFF AS WINNER != A.WINNER,
LIKE_FIRST AS WINNER = A.WINNER
)
ORDER BY MATCH#;
NON_WINNING_YEARS
This presentation is available in http://db-oriented.com/presentations
©
Oren
Nakdimon
©
Oren
Nakdimon
FROM_YEAR
TO_YEAR
9
WINNER
SELECT MATCH#, WINNER, FROM_YEAR, TO_YEAR,
NON_WINNER_YEARS
FROM (SELECT * FROM EUROVISION_WINNERS
WHERE YEAR BETWEEN 1971 AND 1991)
MATCH_RECOGNIZE (
ORDER BY YEAR
MEASURES
MATCH_NUMBER() MATCH#,
A.WINNER WINNER,
FIRST(YEAR) FROM_YEAR,
LAST(YEAR) TO_YEAR,
COUNT(DIFF.*) NON_WINNER_YEARS
ONE ROW PER MATCH
AFTER MATCH SKIP TO FIRST DIFF
PATTERN (A SAME* DIFF+ LIKE_FIRST+)
DEFINE
SAME AS WINNER = PREV(WINNER),
DIFF AS WINNER != A.WINNER,
LIKE_FIRST AS WINNER = A.WINNER
)
ORDER BY MATCH#;
NON_WINNING_YEARS
This presentation is available in http://db-oriented.com/presentations
©
Oren
Nakdimon
©
Oren
Nakdimon
FROM_YEAR
TO_YEAR
9
WINNER
SELECT MATCH#, WINNER, FROM_YEAR, TO_YEAR,
NON_WINNER_YEARS
FROM (SELECT * FROM EUROVISION_WINNERS
WHERE YEAR BETWEEN 1971 AND 1991)
MATCH_RECOGNIZE (
ORDER BY YEAR
MEASURES
MATCH_NUMBER() MATCH#,
A.WINNER WINNER,
FIRST(YEAR) FROM_YEAR,
LAST (YEAR) TO_YEAR,
COUNT(DIFF.*) NON_WINNER_YEARS
ONE ROW PER MATCH
AFTER MATCH SKIP TO FIRST DIFF
PATTERN (A SAME* DIFF+ LIKE_FIRST+)
DEFINE
SAME AS WINNER = PREV(WINNER),
DIFF AS WINNER != A.WINNER,
LIKE_FIRST AS WINNER = A.WINNER
)
ORDER BY MATCH#;
NON_WINNING_YEARS
This presentation is available in http://db-oriented.com/presentations
©
Oren
Nakdimon
©
Oren
Nakdimon
FROM_YEAR
TO_YEAR
9
WINNER
SELECT MATCH#, WINNER, FROM_YEAR, TO_YEAR,
NON_WINNER_YEARS
FROM (SELECT * FROM EUROVISION_WINNERS
WHERE YEAR BETWEEN 1971 AND 1991)
MATCH_RECOGNIZE (
ORDER BY YEAR
MEASURES
MATCH_NUMBER() MATCH#,
A.WINNER WINNER,
FIRST(YEAR) FROM_YEAR,
LAST (YEAR) TO_YEAR,
COUNT(DIFF.*) NON_WINNER_YEARS
ONE ROW PER MATCH
AFTER MATCH SKIP TO FIRST DIFF
PATTERN (A SAME* DIFF+ LIKE_FIRST+)
DEFINE
SAME AS WINNER = PREV(WINNER),
DIFF AS WINNER != A.WINNER,
LIKE_FIRST AS WINNER = A.WINNER
)
ORDER BY MATCH#;
NON_WINNING_YEARS
COUNT
MAX
MIN
SUM
AVG
This presentation is available in http://db-oriented.com/presentations
©
Oren
Nakdimon
©
Oren
Nakdimon
FROM_YEAR
TO_YEAR
9
WINNER
SELECT MATCH#, WINNER, FROM_YEAR, TO_YEAR,
NON_WINNER_YEARS
FROM (SELECT * FROM EUROVISION_WINNERS
WHERE YEAR BETWEEN 1971 AND 1991)
MATCH_RECOGNIZE (
ORDER BY YEAR
MEASURES
MATCH_NUMBER() MATCH#,
A.WINNER WINNER,
FIRST(YEAR) FROM_YEAR,
LAST (YEAR) TO_YEAR,
COUNT(DIFF.*) NON_WINNER_YEARS
ONE ROW PER MATCH
AFTER MATCH SKIP TO FIRST DIFF
PATTERN (A SAME* DIFF+ LIKE_FIRST+)
DEFINE
SAME AS WINNER = PREV(WINNER),
DIFF AS WINNER != A.WINNER,
LIKE_FIRST AS WINNER = A.WINNER
)
ORDER BY MATCH#;
NON_WINNING_YEARS
This presentation is available in http://db-oriented.com/presentations
©
Oren
Nakdimon
©
Oren
Nakdimon
FROM_YEAR
TO_YEAR
9
WINNER
NON_WINNING_YEARS
SELECT MATCH#, WINNER, FROM_YEAR, TO_YEAR,
NON_WINNER_YEARS
FROM (SELECT * FROM EUROVISION_WINNERS
WHERE YEAR BETWEEN 1971 AND 1991)
MATCH_RECOGNIZE (
ORDER BY YEAR
MEASURES
MATCH_NUMBER() MATCH#,
A.WINNER WINNER,
FIRST(YEAR) FROM_YEAR,
LAST (YEAR) TO_YEAR,
COUNT(DIFF.*) NON_WINNER_YEARS
ONE ROW PER MATCH
AFTER MATCH SKIP TO FIRST DIFF
PATTERN (A SAME* DIFF+ LIKE_FIRST+)
DEFINE
SAME AS WINNER = PREV(WINNER),
DIFF AS WINNER != A.WINNER,
LIKE_FIRST AS WINNER = A.WINNER
)
ORDER BY MATCH#;
This presentation is available in http://db-oriented.com/presentations
©
Oren
Nakdimon
©
Oren
Nakdimon
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))
);
This presentation is available in http://db-oriented.com/presentations
©
Oren
Nakdimon
©
Oren
Nakdimon
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))
);
This presentation is available in http://db-oriented.com/presentations
©
Oren
Nakdimon
©
Oren
Nakdimon
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))
);
This presentation is available in http://db-oriented.com/presentations
©
Oren
Nakdimon
©
Oren
Nakdimon
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))
);
This presentation is available in http://db-oriented.com/presentations
©
Oren
Nakdimon
©
Oren
Nakdimon
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))
);
NF















Implicit Pattern
Variable
This presentation is available in http://db-oriented.com/presentations
©
Oren
Nakdimon
©
Oren
Nakdimon
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
NF















Implicit Pattern
Variable
This presentation is available in http://db-oriented.com/presentations
©
Oren
Nakdimon
©
Oren
Nakdimon
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
Grouping
NF















Implicit Pattern
Variable
This presentation is available in http://db-oriented.com/presentations
©
Oren
Nakdimon
©
Oren
Nakdimon
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))
);
NF















Implicit Pattern
Variable
This presentation is available in http://db-oriented.com/presentations
©
Oren
Nakdimon
©
Oren
Nakdimon
Fibonacci Numbers
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))
);
This presentation is available in http://db-oriented.com/presentations
©
Oren
Nakdimon
©
Oren
Nakdimon
Fibonacci Numbers
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
©
Oren
Nakdimon
©
Oren
Nakdimon
Fibonacci Numbers
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))
);
This presentation is available in http://db-oriented.com/presentations
©
Oren
Nakdimon
©
Oren
Nakdimon
Additional Resources
 The Documentation:
https://docs.oracle.com/en/database/oracle/oracle-
database/18/dwhsg/sql-pattern-matching-data-warehouses.html
 Keith Laker’s blog: https://oracle-big-data.blogspot.com/
 Stew Ashton’s blog:
https://stewashton.wordpress.com/category/match_recognize/
THANK YOU
Oren Nakdimon
www.db-oriented.com
 oren@db-oriented.com
 +972-54-4393763
@DBoriented

More Related Content

Recently uploaded

Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...HostedbyConfluent
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...gurkirankumar98700
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
Google AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGGoogle AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGSujit Pal
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 

Recently uploaded (20)

Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
Google AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGGoogle AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAG
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 

Featured

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by HubspotMarius Sescu
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTExpeed Software
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsPixeldarts
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 

Featured (20)

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 

Oren Nakdimon - Oracle SQL Pattern Matching Made Easy

  • 1. Oracle 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 © Oren Nakdimon © Oren Nakdimon MATCH_RECOGNIZE  Added in Oracle 12cR1  Enhanced analysis of row sequences  For detecting matches to complex patterns  A significant boost to the analytical capabilities of SQL  Very powerful With Great Power Comes Complex Syntax
  • 3. This presentation is available in http://db-oriented.com/presentations © Oren Nakdimon © Oren Nakdimon Agenda  Start using Pattern Matching  Step by step  Not all the capabilities…  But all the essentials (and more)  Simple examples  Recommended resources
  • 4. This presentation is available in http://db-oriented.com/presentations © Oren Nakdimon © Oren Nakdimon http://db-oriented.com Who Am I?
  • 5. This presentation is available in http://db-oriented.com/presentations © Oren Nakdimon © Oren Nakdimon 1956 Switzerland Refrain Lys Assia French Switzerland 1957 Netherlands Net als toen Corry Brokken 31 Dutch Germany 1958 France Dors, mon amour André Claveau 27 French Netherlands 1959 Netherlands Een beetje Teddy Scholten 21 Dutch France 1960 France Tom Pillibi Jacqueline Boyer 32 French United Kingdom 1961 Luxembourg Nous les amoureux Jean-Claude Pascal 31 French France 1962 France Un premier amour Isabelle Aubret 26 French Luxembourg 1963 Denmark Dansevise Grethe and Jørgen Ingmann 42 Danish United Kingdom 1964 Italy Non ho l'età Gigliola Cinquetti 49 Italian Denmark 1965 Luxembourg Poupée de cire, poupée de son France Gall 32 French Italy 1966 Austria Merci, Chérie Udo Jürgens 31 German Luxembourg 1967 United Kingdom Puppet on a String Sandie Shaw 47 English Austria 1968 Spain La, la, la Massiel 29 Spanish United Kingdom 1969 Netherlands De troubadour Lenny Kuhr 18 Dutch Spain 1970 Ireland All Kinds of Everything Dana 32 English Netherlands 1971 Monaco Un banc, un arbre, une rue Séverine 128 French Ireland 1972 Luxembourg Après toi Vicky Leandros 128 French United Kingdom 1973 Luxembourg Tu te reconnaîtras Anne-Marie David 129 French Luxembourg YEAR WINNER SONG PERFORMER POINTS LANGUAGE HOST
  • 6. This presentation is available in http://db-oriented.com/presentations © Oren Nakdimon © Oren Nakdimon Find all the wins of Luxembourg SELECT * FROM EUROVISION_WINNERS WHERE WINNER = 'Luxembourg';
  • 7. This presentation is available in http://db-oriented.com/presentations © Oren Nakdimon © Oren Nakdimon YEAR WINNER SONG HOST 1960 France Tom Pillibi United Kingdom 1961 Luxembourg Nous les amoureux France 1962 France Un premier amour Luxembourg 1963 Denmark Dansevise United Kingdom 1964 Italy Non ho l'età Denmark 1965 Luxembourg Poupée de cire, poupée de son Italy 1966 Austria Merci, Chérie Luxembourg 1967 United Kingdom Puppet on a String Austria 1968 Spain La, la, la United Kingdom 1969 Netherlands De troubadour Spain 1970 Ireland All Kinds of Everything Netherlands 1971 Monaco Un banc, un arbre, une rue Ireland 1972 Luxembourg Après toi United Kingdom 1973 Luxembourg Tu te reconnaîtras Luxembourg 1974 Sweden Waterloo United Kingdom 1975 Netherlands Ding-a-dong Sweden 1976 United Kingdom Save Your Kisses for Me Netherlands 1977 France L'oiseau et l'enfant United Kingdom 1978 Israel A-Ba-Ni-Bi France Find all the wins of Luxembourg     Pattern Variable 1 2 3 4 LUX SELECT YEAR, WINNER, SONG, HOST FROM EUROVISION_WINNERS MATCH_RECOGNIZE ( ALL ROWS PER MATCH PATTERN (LUX) DEFINE LUX AS WINNER = 'Luxembourg' )
  • 8. This presentation is available in http://db-oriented.com/presentations © Oren Nakdimon © Oren Nakdimon YEAR WINNER SONG HOST 1960 France Tom Pillibi United Kingdom 1961 Luxembourg Nous les amoureux France 1962 France Un premier amour Luxembourg 1963 Denmark Dansevise United Kingdom 1964 Italy Non ho l'età Denmark 1965 Luxembourg Poupée de cire, poupée de son Italy 1966 Austria Merci, Chérie Luxembourg 1967 United Kingdom Puppet on a String Austria 1968 Spain La, la, la United Kingdom 1969 Netherlands De troubadour Spain 1970 Ireland All Kinds of Everything Netherlands 1971 Monaco Un banc, un arbre, une rue Ireland 1972 Luxembourg Après toi United Kingdom 1973 Luxembourg Tu te reconnaîtras Luxembourg 1974 Sweden Waterloo United Kingdom 1975 Netherlands Ding-a-dong Sweden 1976 United Kingdom Save Your Kisses for Me Netherlands 1977 France L'oiseau et l'enfant United Kingdom 1978 Israel A-Ba-Ni-Bi France Find 2 successive wins of Luxembourg SELECT * FROM EUROVISION_WINNERS WHERE WINNER = 'Luxembourg';
  • 9. This presentation is available in http://db-oriented.com/presentations © Oren Nakdimon © Oren Nakdimon YEAR WINNER SONG HOST 1960 France Tom Pillibi United Kingdom 1961 Luxembourg Nous les amoureux France 1962 France Un premier amour Luxembourg 1963 Denmark Dansevise United Kingdom 1964 Italy Non ho l'età Denmark 1965 Luxembourg Poupée de cire, poupée de son Italy 1966 Austria Merci, Chérie Luxembourg 1967 United Kingdom Puppet on a String Austria 1968 Spain La, la, la United Kingdom 1969 Netherlands De troubadour Spain 1970 Ireland All Kinds of Everything Netherlands 1971 Monaco Un banc, un arbre, une rue Ireland 1972 Luxembourg Après toi United Kingdom 1973 Luxembourg Tu te reconnaîtras Luxembourg 1974 Sweden Waterloo United Kingdom 1975 Netherlands Ding-a-dong Sweden 1976 United Kingdom Save Your Kisses for Me Netherlands 1977 France L'oiseau et l'enfant United Kingdom 1978 Israel A-Ba-Ni-Bi France Find 2 successive wins of Luxembourg     Pattern Variable SELECT YEAR, WINNER, SONG, HOST FROM EUROVISION_WINNERS MATCH_RECOGNIZE ( ORDER BY YEAR ALL ROWS PER MATCH PATTERN (LUX LUX) DEFINE LUX AS WINNER = 'Luxembourg' ) 1 LUX order by
  • 10. This presentation is available in http://db-oriented.com/presentations © Oren Nakdimon © Oren Nakdimon Variables Pattern
  • 11. This presentation is available in http://db-oriented.com/presentations © Oren Nakdimon © Oren Nakdimon YEAR WINNER SONG HOST 1960 France Tom Pillibi United Kingdom 1961 Luxembourg Nous les amoureux France 1962 France Un premier amour Luxembourg 1963 Denmark Dansevise United Kingdom 1964 Italy Non ho l'età Denmark 1965 Luxembourg Poupée de cire, poupée de son Italy 1966 Austria Merci, Chérie Luxembourg 1967 United Kingdom Puppet on a String Austria 1968 Spain La, la, la United Kingdom 1969 Netherlands De troubadour Spain 1970 Ireland All Kinds of Everything Netherlands 1971 Monaco Un banc, un arbre, une rue Ireland 1972 Luxembourg Après toi United Kingdom 1973 Luxembourg Tu te reconnaîtras Luxembourg 1974 Sweden Waterloo United Kingdom 1975 Netherlands Ding-a-dong Sweden 1976 United Kingdom Save Your Kisses for Me Netherlands 1977 France L'oiseau et l'enfant United Kingdom 1978 Israel A-Ba-Ni-Bi France Find 2 successive wins of Luxembourg   Pattern Variable SELECT YEAR, WINNER, SONG, HOST FROM EUROVISION_WINNERS MATCH_RECOGNIZE ( ORDER BY YEAR ALL ROWS PER MATCH PATTERN (LUX LUX) DEFINE LUX AS WINNER = 'Luxembourg' ) 1 LUX order by
  • 12. This presentation is available in http://db-oriented.com/presentations © Oren Nakdimon © Oren Nakdimon Find 2 successive wins of Luxembourg SELECT YEAR, WINNER, SONG, HOST FROM EUROVISION_WINNERS MATCH_RECOGNIZE ( ORDER BY YEAR ALL ROWS PER MATCH PATTERN (LUX LUX) DEFINE LUX AS WINNER = 'Luxembourg' )
  • 13. This presentation is available in http://db-oriented.com/presentations © Oren Nakdimon © Oren Nakdimon Find 2 successive wins of Luxembourg SELECT YEAR, WINNER, SONG, HOST FROM EUROVISION_WINNERS MATCH_RECOGNIZE ( ORDER BY YEAR ALL ROWS PER MATCH PATTERN (LUX{2}) DEFINE LUX AS WINNER = 'Luxembourg' )
  • 14. This presentation is available in http://db-oriented.com/presentations © Oren Nakdimon © Oren Nakdimon PATTERN Quantifiers Pattern Number of consecutive occurrences X 1 X{n} n X{n,} n or more X* 0 or more X{n,m} between n and m X{,m} between 0 and m X? 0 or 1 X+ 1 or more
  • 15. This presentation is available in http://db-oriented.com/presentations © Oren Nakdimon © Oren Nakdimon YEAR WINNER SONG HOST 1960 France Tom Pillibi United Kingdom 1961 Luxembourg Nous les amoureux France 1962 France Un premier amour Luxembourg 1963 Denmark Dansevise United Kingdom 1964 Italy Non ho l'età Denmark 1965 Luxembourg Poupée de cire, poupée de son Italy 1966 Austria Merci, Chérie Luxembourg 1967 United Kingdom Puppet on a String Austria 1968 Spain La, la, la United Kingdom 1969 Netherlands De troubadour Spain 1970 Ireland All Kinds of Everything Netherlands 1971 Monaco Un banc, un arbre, une rue Ireland 1972 Luxembourg Après toi United Kingdom 1973 Luxembourg Tu te reconnaîtras Luxembourg 1974 Sweden Waterloo United Kingdom 1975 Netherlands Ding-a-dong Sweden 1976 United Kingdom Save Your Kisses for Me Netherlands 1977 France L'oiseau et l'enfant United Kingdom 1978 Israel A-Ba-Ni-Bi France Find one or more successive wins of Luxembourg     Pattern Variable SELECT YEAR, WINNER, SONG, HOST FROM EUROVISION_WINNERS MATCH_RECOGNIZE ( ORDER BY YEAR ALL ROWS PER MATCH PATTERN (LUX+) DEFINE LUX AS WINNER = 'Luxembourg' ) 1 2 3 LUX order by
  • 16. This presentation is available in http://db-oriented.com/presentations © Oren Nakdimon © Oren Nakdimon SELECT YEAR, WINNER, SONG, HOST FROM EUROVISION_WINNERS MATCH_RECOGNIZE ( ORDER BY YEAR ALL ROWS PER MATCH PATTERN (LUX) DEFINE LUX AS WINNER = 'Luxembourg' ) SELECT YEAR, WINNER, SONG, HOST FROM EUROVISION_WINNERS MATCH_RECOGNIZE ( ORDER BY YEAR ALL ROWS PER MATCH PATTERN (LUX+) DEFINE LUX AS WINNER = 'Luxembourg' )
  • 17. This presentation is available in http://db-oriented.com/presentations © Oren Nakdimon © Oren Nakdimon A match is a consecutive sequence of (zero, one, or more) records, that matches a specific pattern
  • 18. This presentation is available in http://db-oriented.com/presentations © Oren Nakdimon © Oren Nakdimon SELECT YEAR, WINNER, SONG, HOST FROM EUROVISION_WINNERS MATCH_RECOGNIZE ( ORDER BY YEAR MEASURES MATCH_NUMBER() AS MATCH# ALL ROWS PER MATCH PATTERN (LUX) DEFINE LUX AS WINNER = 'Luxembourg' ) SELECT YEAR, WINNER, SONG, HOST FROM EUROVISION_WINNERS MATCH_RECOGNIZE ( ORDER BY YEAR MEASURES MATCH_NUMBER() AS MATCH# ALL ROWS PER MATCH PATTERN (LUX+) DEFINE LUX AS WINNER = 'Luxembourg' )
  • 19. This presentation is available in http://db-oriented.com/presentations © Oren Nakdimon © Oren Nakdimon SELECT MATCH#, YEAR, WINNER, SONG, HOST FROM EUROVISION_WINNERS MATCH_RECOGNIZE ( ORDER BY YEAR MEASURES MATCH_NUMBER() AS MATCH# ALL ROWS PER MATCH PATTERN (LUX) DEFINE LUX AS WINNER = 'Luxembourg' ) SELECT MATCH#, YEAR, WINNER, SONG, HOST FROM EUROVISION_WINNERS MATCH_RECOGNIZE ( ORDER BY YEAR MEASURES MATCH_NUMBER() AS MATCH# ALL ROWS PER MATCH PATTERN (LUX+) DEFINE LUX AS WINNER = 'Luxembourg' )
  • 20. This presentation is available in http://db-oriented.com/presentations © Oren Nakdimon © Oren Nakdimon MATCH_RECOGNIZE
  • 21. This presentation is available in http://db-oriented.com/presentations © Oren Nakdimon © Oren Nakdimon Input and Output SELECT * FROM (SELECT YEAR, WINNER, SONG, PERFORMER, HOST FROM EUROVISION_WINNERS WHERE YEAR BETWEEN 1990 AND 2000) MATCH_RECOGNIZE ( ORDER BY YEAR MEASURES MATCH_NUMBER() AS MATCH# ALL ROWS PER MATCH PATTERN (I L UK?) DEFINE I AS WINNER LIKE 'I%', LN AS LENGTH(SONG)>=18, UK AS HOST='United Kingdom' );
  • 22. This presentation is available in http://db-oriented.com/presentations © Oren Nakdimon © Oren Nakdimon Input and Output SELECT * FROM (SELECT YEAR, WINNER, SONG, PERFORMER, HOST FROM EUROVISION_WINNERS WHERE YEAR BETWEEN 1990 AND 2000) MATCH_RECOGNIZE ( ORDER BY YEAR MEASURES MATCH_NUMBER() AS MATCH# ALL ROWS PER MATCH PATTERN (I L UK?) DEFINE I AS WINNER LIKE 'I%', LN AS LENGTH(SONG)>=18, UK AS HOST='United Kingdom' );
  • 23. This presentation is available in http://db-oriented.com/presentations © Oren Nakdimon © Oren Nakdimon SELECT * FROM (SELECT YEAR, WINNER, SONG, HOST FROM EUROVISION_WINNERS WHERE YEAR BETWEEN 1990 AND 2000) MATCH_RECOGNIZE ( ORDER BY YEAR MEASURES MATCH_NUMBER() AS MATCH# ALL ROWS PER MATCH PATTERN (I L UK?) DEFINE I AS WINNER LIKE 'I%', LN AS LENGTH(SONG)>=18, UK AS HOST='United Kingdom' ); Input and Output
  • 24. This presentation is available in http://db-oriented.com/presentations © Oren Nakdimon © Oren Nakdimon SELECT * FROM (SELECT YEAR, WINNER, SONG, HOST FROM EUROVISION_WINNERS WHERE YEAR BETWEEN 1990 AND 2000) MATCH_RECOGNIZE ( ORDER BY YEAR MEASURES MATCH_NUMBER() AS MATCH# ALL ROWS PER MATCH PATTERN (I L UK?) DEFINE I AS WINNER LIKE 'I%', LN AS LENGTH(SONG)>=18, UK AS HOST='United Kingdom' ); Input and Output YEAR WINNER SONG HOST 1990 Italy Insieme: 1992 Yugoslavia 1991 Sweden Fångad av en stormvind Italy 1992 Ireland Why Me? Sweden 1993 Ireland In Your Eyes Ireland 1994 Ireland Rock 'n' Roll Kids Ireland 1995 Norway Nocturne Ireland 1996 Ireland The Voice Norway 1997 United Kingdom Love Shine a Light Ireland 1998 Israel Diva United Kingdom 1999 Sweden Take Me to Your Heaven Israel 2000 Denmark Fly on the Wings of Love Sweden
  • 25. This presentation is available in http://db-oriented.com/presentations © Oren Nakdimon © Oren Nakdimon Multiple Pattern Variables YEAR WINNER SONG HOST 1990 Italy Insieme: 1992 Yugoslavia 1991 Sweden Fångad av en stormvind Italy 1992 Ireland Why Me? Sweden 1993 Ireland In Your Eyes Ireland 1994 Ireland Rock 'n' Roll Kids Ireland 1995 Norway Nocturne Ireland 1996 Ireland The Voice Norway 1997 United Kingdom Love Shine a Light Ireland 1998 Israel Diva United Kingdom 1999 Sweden Take Me to Your Heaven Israel 2000 Denmark Fly on the Wings of Love Sweden SELECT * FROM (SELECT YEAR, WINNER, SONG, HOST FROM EUROVISION_WINNERS WHERE YEAR BETWEEN 1990 AND 2000) MATCH_RECOGNIZE ( ORDER BY YEAR MEASURES MATCH_NUMBER() AS MATCH# ALL ROWS PER MATCH PATTERN (I LN UK?) DEFINE I AS WINNER LIKE 'I%', LN AS LENGTH(SONG)>=18, UK AS HOST='United Kingdom' ); order by
  • 26. This presentation is available in http://db-oriented.com/presentations © Oren Nakdimon © Oren Nakdimon SELECT * FROM (SELECT YEAR, WINNER, SONG, PERFORMER, HOST FROM EUROVISION_WINNERS WHERE YEAR BETWEEN 1990 AND 2000) MATCH_RECOGNIZE ( ORDER BY YEAR MEASURES MATCH_NUMBER() AS MATCH# ALL ROWS PER MATCH PATTERN (I LN UK?) DEFINE I AS WINNER LIKE 'I%', LN AS LENGTH(SONG)>=18, UK AS HOST='United Kingdom' ); Multiple Pattern Variables YEAR WINNER SONG HOST 1990 Italy Insieme: 1992 Yugoslavia 1991 Sweden Fångad av en stormvind Italy 1992 Ireland Why Me? Sweden 1993 Ireland In Your Eyes Ireland 1994 Ireland Rock 'n' Roll Kids Ireland 1995 Norway Nocturne Ireland 1996 Ireland The Voice Norway 1997 United Kingdom Love Shine a Light Ireland 1998 Israel Diva United Kingdom 1999 Sweden Take Me to Your Heaven Israel 2000 Denmark Fly on the Wings of Love Sweden order by
  • 27. This presentation is available in http://db-oriented.com/presentations © Oren Nakdimon © Oren Nakdimon SELECT * FROM (SELECT YEAR, WINNER, SONG, PERFORMER, HOST FROM EUROVISION_WINNERS WHERE YEAR BETWEEN 1990 AND 2000) MATCH_RECOGNIZE ( ORDER BY YEAR MEASURES MATCH_NUMBER() AS MATCH# ALL ROWS PER MATCH PATTERN (I LN UK?) DEFINE I AS WINNER LIKE 'I%', LN AS LENGTH(SONG)>=18, UK AS HOST='United Kingdom' ); Multiple Pattern Variables YEAR WINNER SONG HOST 1990 Italy Insieme: 1992 Yugoslavia 1991 Sweden Fångad av en stormvind Italy 1992 Ireland Why Me? Sweden 1993 Ireland In Your Eyes Ireland 1994 Ireland Rock 'n' Roll Kids Ireland 1995 Norway Nocturne Ireland 1996 Ireland The Voice Norway 1997 United Kingdom Love Shine a Light Ireland 1998 Israel Diva United Kingdom 1999 Sweden Take Me to Your Heaven Israel 2000 Denmark Fly on the Wings of Love Sweden I ? ? ? ? ? ? Pattern Variables order by
  • 28. This presentation is available in http://db-oriented.com/presentations © Oren Nakdimon © Oren Nakdimon SELECT * FROM (SELECT YEAR, WINNER, SONG, PERFORMER, HOST FROM EUROVISION_WINNERS WHERE YEAR BETWEEN 1990 AND 2000) MATCH_RECOGNIZE ( ORDER BY YEAR MEASURES MATCH_NUMBER() AS MATCH# ALL ROWS PER MATCH PATTERN (I LN UK?) DEFINE I AS WINNER LIKE 'I%', LN AS LENGTH(SONG)>=18, UK AS HOST='United Kingdom' ); Multiple Pattern Variables YEAR WINNER SONG HOST 1990 Italy Insieme: 1992 Yugoslavia 1991 Sweden Fångad av en stormvind Italy 1992 Ireland Why Me? Sweden 1993 Ireland In Your Eyes Ireland 1994 Ireland Rock 'n' Roll Kids Ireland 1995 Norway Nocturne Ireland 1996 Ireland The Voice Norway 1997 United Kingdom Love Shine a Light Ireland 1998 Israel Diva United Kingdom 1999 Sweden Take Me to Your Heaven Israel 2000 Denmark Fly on the Wings of Love Sweden I ? ? ? ? ? ? LN ? ? ? ? ? Pattern Variables order by
  • 29. This presentation is available in http://db-oriented.com/presentations © Oren Nakdimon © Oren Nakdimon SELECT * FROM (SELECT YEAR, WINNER, SONG, PERFORMER, HOST FROM EUROVISION_WINNERS WHERE YEAR BETWEEN 1990 AND 2000) MATCH_RECOGNIZE ( ORDER BY YEAR MEASURES MATCH_NUMBER() AS MATCH# ALL ROWS PER MATCH PATTERN (I LN UK?) DEFINE I AS WINNER LIKE 'I%', LN AS LENGTH(SONG)>=18, UK AS HOST='United Kingdom' ); Multiple Pattern Variables YEAR WINNER SONG HOST 1990 Italy Insieme: 1992 Yugoslavia 1991 Sweden Fångad av en stormvind Italy 1992 Ireland Why Me? Sweden 1993 Ireland In Your Eyes Ireland 1994 Ireland Rock 'n' Roll Kids Ireland 1995 Norway Nocturne Ireland 1996 Ireland The Voice Norway 1997 United Kingdom Love Shine a Light Ireland 1998 Israel Diva United Kingdom 1999 Sweden Take Me to Your Heaven Israel 2000 Denmark Fly on the Wings of Love Sweden I ? ? ? ? ? ? LN ? ? ? ? ? UK ? Pattern Variables order by
  • 30. This presentation is available in http://db-oriented.com/presentations © Oren Nakdimon © Oren Nakdimon UK LN I SELECT * FROM (SELECT YEAR, WINNER, SONG, PERFORMER, HOST FROM EUROVISION_WINNERS WHERE YEAR BETWEEN 1990 AND 2000) MATCH_RECOGNIZE ( ORDER BY YEAR MEASURES MATCH_NUMBER() AS MATCH# ALL ROWS PER MATCH PATTERN (I LN UK?) DEFINE I AS WINNER LIKE 'I%', LN AS LENGTH(SONG)>=18, UK AS HOST='United Kingdom' );     Multiple Pattern Variables 1 2 3 YEAR WINNER SONG HOST 1990 Italy Insieme: 1992 Yugoslavia 1991 Sweden Fångad av en stormvind Italy 1992 Ireland Why Me? Sweden 1993 Ireland In Your Eyes Ireland 1994 Ireland Rock 'n' Roll Kids Ireland 1995 Norway Nocturne Ireland 1996 Ireland The Voice Norway 1997 United Kingdom Love Shine a Light Ireland 1998 Israel Diva United Kingdom 1999 Sweden Take Me to Your Heaven Israel 2000 Denmark Fly on the Wings of Love Sweden Pattern Variables order by    
  • 31. This presentation is available in http://db-oriented.com/presentations © Oren Nakdimon © Oren Nakdimon UK LN I     Multiple Pattern Variables 1 2 3 YEAR WINNER SONG HOST 1990 Italy Insieme: 1992 Yugoslavia 1991 Sweden Fångad av en stormvind Italy 1992 Ireland Why Me? Sweden 1993 Ireland In Your Eyes Ireland 1994 Ireland Rock 'n' Roll Kids Ireland 1995 Norway Nocturne Ireland 1996 Ireland The Voice Norway 1997 United Kingdom Love Shine a Light Ireland 1998 Israel Diva United Kingdom 1999 Sweden Take Me to Your Heaven Israel 2000 Denmark Fly on the Wings of Love Sweden Pattern Variables order by     SELECT * FROM (SELECT YEAR, WINNER, SONG, HOST FROM EUROVISION_WINNERS WHERE YEAR BETWEEN 1990 AND 2000) MATCH_RECOGNIZE ( ORDER BY YEAR MEASURES MATCH_NUMBER() AS MATCH# ALL ROWS PER MATCH PATTERN (I LN UK?) DEFINE I AS WINNER LIKE 'I%', LN AS LENGTH(SONG)>=18, UK AS HOST='United Kingdom' );
  • 32. This presentation is available in http://db-oriented.com/presentations © Oren Nakdimon © Oren Nakdimon Find two or more successive wins of the same country   YEAR WINNER SONG HOST 1977 France L'oiseau et l'enfant United Kingdom 1978 Israel A-Ba-Ni-Bi France 1979 Israel Hallelujah Israel 1980 Ireland What's Another Year Netherlands 1981 United Kingdom Making Your Mind Up Ireland 1982 Germany Ein bißchen Frieden United Kingdom 1983 Luxembourg Si la vie est cadeau Germany 1984 Sweden Diggi-Loo Diggi-Ley Luxembourg 1985 Norway La det swinge Sweden 1986 Belgium J'aime la vie Norway 1987 Ireland Hold Me Now Belgium 1988 Switzerland Ne partez pas sans moi Ireland 1989 Yugoslavia Rock Me Switzerland 1990 Italy Insieme: 1992 Yugoslavia 1991 Sweden Fångad av en stormvind Italy 1992 Ireland Why Me? Sweden 1993 Ireland In Your Eyes Ireland 1994 Ireland Rock 'n' Roll Kids Ireland 1995 Norway Nocturne Ireland X SAME SELECT MATCH#, YEAR, WINNER, SONG, HOST FROM EUROVISION_WINNERS MATCH_RECOGNIZE ( ORDER BY YEAR MEASURES MATCH_NUMBER() AS MATCH# ALL ROWS PER MATCH PATTERN (X SAME+) DEFINE SAME AS WINNER = PREV(WINNER) );                Implicit Pattern Variable PREV NEXT
  • 33. This presentation is available in http://db-oriented.com/presentations © Oren Nakdimon © Oren Nakdimon Find returning winners after a break YEAR WINNER SONG POINTS 1971 Monaco Un banc, un arbre, une rue 128 1972 Luxembourg Après toi 128 1973 Luxembourg Tu te reconnaîtras 129 1974 Sweden Waterloo 24 1975 Netherlands Ding-a-dong 152 1976 United Kingdom Save Your Kisses for Me 164 1977 France L'oiseau et l'enfant 136 1978 Israel A-Ba-Ni-Bi 157 1979 Israel Hallelujah 125 1980 Ireland What's Another Year 143 1981 United Kingdom Making Your Mind Up 136 1982 Germany Ein bißchen Frieden 161 1983 Luxembourg Si la vie est cadeau 142 1984 Sweden Diggi-Loo Diggi-Ley 145 1985 Norway La det swinge 123 1986 Belgium J'aime la vie 176 1987 Ireland Hold Me Now 172 1988 Switzerland Ne partez pas sans moi 137 1989 Yugoslavia Rock Me 137 1990 Italy Insieme: 1992 149 1991 Sweden Fångad av en stormvind 146
  • 34. This presentation is available in http://db-oriented.com/presentations © Oren Nakdimon © Oren Nakdimon Find returning winners after a break YEAR WINNER SONG POINTS 1971 Monaco Un banc, un arbre, une rue 128 1972 Luxembourg Après toi 128 1973 Luxembourg Tu te reconnaîtras 129 1974 Sweden Waterloo 24 1975 Netherlands Ding-a-dong 152 1976 United Kingdom Save Your Kisses for Me 164 1977 France L'oiseau et l'enfant 136 1978 Israel A-Ba-Ni-Bi 157 1979 Israel Hallelujah 125 1980 Ireland What's Another Year 143 1981 United Kingdom Making Your Mind Up 136 1982 Germany Ein bißchen Frieden 161 1983 Luxembourg Si la vie est cadeau 142 1984 Sweden Diggi-Loo Diggi-Ley 145 1985 Norway La det swinge 123 1986 Belgium J'aime la vie 176 1987 Ireland Hold Me Now 172 1988 Switzerland Ne partez pas sans moi 137 1989 Yugoslavia Rock Me 137 1990 Italy Insieme: 1992 149 1991 Sweden Fångad av en stormvind 146 SELECT MATCH#, YEAR, WINNER, SONG, POINTS, CLS FROM (SELECT * FROM EUROVISION_WINNERS WHERE YEAR BETWEEN 1971 AND 1991) MATCH_RECOGNIZE ( ORDER BY YEAR MEASURES MATCH_NUMBER() MATCH#, CLASSIFIER() CLS ALL ROWS PER MATCH AFTER MATCH SKIP PAST LAST ROW PATTERN (A SAME* DIFF+ LIKE_FIRST+) DEFINE SAME AS WINNER = PREV(WINNER), DIFF AS WINNER != A.WINNER, LIKE_FIRST AS WINNER = A.WINNER ) ORDER BY YEAR;
  • 35. This presentation is available in http://db-oriented.com/presentations © Oren Nakdimon © Oren Nakdimon Find returning winners after a break YEAR WINNER SONG POINTS 1971 Monaco Un banc, un arbre, une rue 128 1972 Luxembourg Après toi 128 1973 Luxembourg Tu te reconnaîtras 129 1974 Sweden Waterloo 24 1975 Netherlands Ding-a-dong 152 1976 United Kingdom Save Your Kisses for Me 164 1977 France L'oiseau et l'enfant 136 1978 Israel A-Ba-Ni-Bi 157 1979 Israel Hallelujah 125 1980 Ireland What's Another Year 143 1981 United Kingdom Making Your Mind Up 136 1982 Germany Ein bißchen Frieden 161 1983 Luxembourg Si la vie est cadeau 142 1984 Sweden Diggi-Loo Diggi-Ley 145 1985 Norway La det swinge 123 1986 Belgium J'aime la vie 176 1987 Ireland Hold Me Now 172 1988 Switzerland Ne partez pas sans moi 137 1989 Yugoslavia Rock Me 137 1990 Italy Insieme: 1992 149 1991 Sweden Fångad av en stormvind 146 SELECT MATCH#, YEAR, WINNER, SONG, POINTS, CLS FROM (SELECT * FROM EUROVISION_WINNERS WHERE YEAR BETWEEN 1971 AND 1991) MATCH_RECOGNIZE ( ORDER BY YEAR MEASURES MATCH_NUMBER() MATCH#, CLASSIFIER() CLS ALL ROWS PER MATCH AFTER MATCH SKIP PAST LAST ROW PATTERN (A SAME* DIFF+ LIKE_FIRST+) DEFINE SAME AS WINNER = PREV(WINNER), DIFF AS WINNER != A.WINNER, LIKE_FIRST AS WINNER = A.WINNER ) ORDER BY YEAR;
  • 36. This presentation is available in http://db-oriented.com/presentations © Oren Nakdimon © Oren Nakdimon Find returning winners after a break YEAR WINNER SONG POINTS 1971 Monaco Un banc, un arbre, une rue 128 1972 Luxembourg Après toi 128 1973 Luxembourg Tu te reconnaîtras 129 1974 Sweden Waterloo 24 1975 Netherlands Ding-a-dong 152 1976 United Kingdom Save Your Kisses for Me 164 1977 France L'oiseau et l'enfant 136 1978 Israel A-Ba-Ni-Bi 157 1979 Israel Hallelujah 125 1980 Ireland What's Another Year 143 1981 United Kingdom Making Your Mind Up 136 1982 Germany Ein bißchen Frieden 161 1983 Luxembourg Si la vie est cadeau 142 1984 Sweden Diggi-Loo Diggi-Ley 145 1985 Norway La det swinge 123 1986 Belgium J'aime la vie 176 1987 Ireland Hold Me Now 172 1988 Switzerland Ne partez pas sans moi 137 1989 Yugoslavia Rock Me 137 1990 Italy Insieme: 1992 149 1991 Sweden Fångad av en stormvind 146 SELECT MATCH#, YEAR, WINNER, SONG, POINTS, CLS FROM (SELECT * FROM EUROVISION_WINNERS WHERE YEAR BETWEEN 1971 AND 1991) MATCH_RECOGNIZE ( ORDER BY YEAR MEASURES MATCH_NUMBER() MATCH#, CLASSIFIER() CLS ALL ROWS PER MATCH AFTER MATCH SKIP PAST LAST ROW PATTERN (A SAME* DIFF+ LIKE_FIRST+) DEFINE SAME AS WINNER = PREV(WINNER), DIFF AS WINNER != A.WINNER, LIKE_FIRST AS WINNER = A.WINNER ) ORDER BY YEAR;
  • 37. This presentation is available in http://db-oriented.com/presentations © Oren Nakdimon © Oren Nakdimon Find returning winners after a break YEAR WINNER SONG POINTS 1971 Monaco Un banc, un arbre, une rue 128 1972 Luxembourg Après toi 128 1973 Luxembourg Tu te reconnaîtras 129 1974 Sweden Waterloo 24 1975 Netherlands Ding-a-dong 152 1976 United Kingdom Save Your Kisses for Me 164 1977 France L'oiseau et l'enfant 136 1978 Israel A-Ba-Ni-Bi 157 1979 Israel Hallelujah 125 1980 Ireland What's Another Year 143 1981 United Kingdom Making Your Mind Up 136 1982 Germany Ein bißchen Frieden 161 1983 Luxembourg Si la vie est cadeau 142 1984 Sweden Diggi-Loo Diggi-Ley 145 1985 Norway La det swinge 123 1986 Belgium J'aime la vie 176 1987 Ireland Hold Me Now 172 1988 Switzerland Ne partez pas sans moi 137 1989 Yugoslavia Rock Me 137 1990 Italy Insieme: 1992 149 1991 Sweden Fångad av en stormvind 146 SELECT MATCH#, YEAR, WINNER, SONG, POINTS, CLS FROM (SELECT * FROM EUROVISION_WINNERS WHERE YEAR BETWEEN 1971 AND 1991) MATCH_RECOGNIZE ( ORDER BY YEAR MEASURES MATCH_NUMBER() MATCH#, CLASSIFIER() CLS ALL ROWS PER MATCH AFTER MATCH SKIP PAST LAST ROW PATTERN (A SAME* DIFF+ LIKE_FIRST+) DEFINE SAME AS WINNER = PREV(WINNER), DIFF AS WINNER != A.WINNER, LIKE_FIRST AS WINNER = A.WINNER ) ORDER BY YEAR;
  • 38. This presentation is available in http://db-oriented.com/presentations © Oren Nakdimon © Oren Nakdimon Find returning winners after a break YEAR WINNER SONG POINTS 1971 Monaco Un banc, un arbre, une rue 128 1972 Luxembourg Après toi 128 1973 Luxembourg Tu te reconnaîtras 129 1974 Sweden Waterloo 24 1975 Netherlands Ding-a-dong 152 1976 United Kingdom Save Your Kisses for Me 164 1977 France L'oiseau et l'enfant 136 1978 Israel A-Ba-Ni-Bi 157 1979 Israel Hallelujah 125 1980 Ireland What's Another Year 143 1981 United Kingdom Making Your Mind Up 136 1982 Germany Ein bißchen Frieden 161 1983 Luxembourg Si la vie est cadeau 142 1984 Sweden Diggi-Loo Diggi-Ley 145 1985 Norway La det swinge 123 1986 Belgium J'aime la vie 176 1987 Ireland Hold Me Now 172 1988 Switzerland Ne partez pas sans moi 137 1989 Yugoslavia Rock Me 137 1990 Italy Insieme: 1992 149 1991 Sweden Fångad av en stormvind 146 SELECT MATCH#, YEAR, WINNER, SONG, POINTS, CLS FROM (SELECT * FROM EUROVISION_WINNERS WHERE YEAR BETWEEN 1971 AND 1991) MATCH_RECOGNIZE ( ORDER BY YEAR MEASURES MATCH_NUMBER() MATCH#, CLASSIFIER() CLS ALL ROWS PER MATCH AFTER MATCH SKIP PAST LAST ROW PATTERN (A SAME* DIFF+ LIKE_FIRST+) DEFINE SAME AS WINNER = PREV(WINNER), DIFF AS WINNER != A.WINNER, LIKE_FIRST AS WINNER = A.WINNER ) ORDER BY YEAR;
  • 39. This presentation is available in http://db-oriented.com/presentations © Oren Nakdimon © Oren Nakdimon Find returning winners after a break YEAR WINNER SONG POINTS 1971 Monaco Un banc, un arbre, une rue 128 1972 Luxembourg Après toi 128 1973 Luxembourg Tu te reconnaîtras 129 1974 Sweden Waterloo 24 1975 Netherlands Ding-a-dong 152 1976 United Kingdom Save Your Kisses for Me 164 1977 France L'oiseau et l'enfant 136 1978 Israel A-Ba-Ni-Bi 157 1979 Israel Hallelujah 125 1980 Ireland What's Another Year 143 1981 United Kingdom Making Your Mind Up 136 1982 Germany Ein bißchen Frieden 161 1983 Luxembourg Si la vie est cadeau 142 1984 Sweden Diggi-Loo Diggi-Ley 145 1985 Norway La det swinge 123 1986 Belgium J'aime la vie 176 1987 Ireland Hold Me Now 172 1988 Switzerland Ne partez pas sans moi 137 1989 Yugoslavia Rock Me 137 1990 Italy Insieme: 1992 149 1991 Sweden Fångad av en stormvind 146 SELECT MATCH#, YEAR, WINNER, SONG, POINTS, CLS FROM (SELECT * FROM EUROVISION_WINNERS WHERE YEAR BETWEEN 1971 AND 1991) MATCH_RECOGNIZE ( ORDER BY YEAR MEASURES MATCH_NUMBER() MATCH#, CLASSIFIER() CLS ALL ROWS PER MATCH AFTER MATCH SKIP PAST LAST ROW PATTERN (A SAME* DIFF+ LIKE_FIRST+) DEFINE SAME AS WINNER = PREV(WINNER), DIFF AS WINNER != A.WINNER, LIKE_FIRST AS WINNER = A.WINNER ) ORDER BY YEAR;
  • 40. This presentation is available in http://db-oriented.com/presentations © Oren Nakdimon © Oren Nakdimon Find returning winners after a break YEAR WINNER SONG POINTS 1971 Monaco Un banc, un arbre, une rue 128 1972 Luxembourg Après toi 128 1973 Luxembourg Tu te reconnaîtras 129 1974 Sweden Waterloo 24 1975 Netherlands Ding-a-dong 152 1976 United Kingdom Save Your Kisses for Me 164 1977 France L'oiseau et l'enfant 136 1978 Israel A-Ba-Ni-Bi 157 1979 Israel Hallelujah 125 1980 Ireland What's Another Year 143 1981 United Kingdom Making Your Mind Up 136 1982 Germany Ein bißchen Frieden 161 1983 Luxembourg Si la vie est cadeau 142 1984 Sweden Diggi-Loo Diggi-Ley 145 1985 Norway La det swinge 123 1986 Belgium J'aime la vie 176 1987 Ireland Hold Me Now 172 1988 Switzerland Ne partez pas sans moi 137 1989 Yugoslavia Rock Me 137 1990 Italy Insieme: 1992 149 1991 Sweden Fångad av en stormvind 146 SELECT MATCH#, YEAR, WINNER, SONG, POINTS, CLS FROM (SELECT * FROM EUROVISION_WINNERS WHERE YEAR BETWEEN 1971 AND 1991) MATCH_RECOGNIZE ( ORDER BY YEAR MEASURES MATCH_NUMBER() MATCH#, CLASSIFIER() CLS ALL ROWS PER MATCH AFTER MATCH SKIP PAST LAST ROW PATTERN (A SAME* DIFF+ LIKE_FIRST+) DEFINE SAME AS WINNER = PREV(WINNER), DIFF AS WINNER != A.WINNER, LIKE_FIRST AS WINNER = A.WINNER ) ORDER BY YEAR;
  • 41. This presentation is available in http://db-oriented.com/presentations © Oren Nakdimon © Oren Nakdimon Find returning winners after a break SELECT MATCH#, YEAR, WINNER, SONG, POINTS, CLS FROM (SELECT * FROM EUROVISION_WINNERS WHERE YEAR BETWEEN 1971 AND 1991) MATCH_RECOGNIZE ( ORDER BY YEAR MEASURES MATCH_NUMBER() MATCH#, CLASSIFIER() CLS ALL ROWS PER MATCH AFTER MATCH SKIP PAST LAST ROW PATTERN (A SAME* DIFF+ LIKE_FIRST+) DEFINE SAME AS WINNER = PREV(WINNER), DIFF AS WINNER != A.WINNER, LIKE_FIRST AS WINNER = A.WINNER ) ORDER BY YEAR;
  • 42. This presentation is available in http://db-oriented.com/presentations © Oren Nakdimon © Oren Nakdimon SELECT MATCH#, YEAR, WINNER, SONG, POINTS, CLS FROM (SELECT * FROM EUROVISION_WINNERS WHERE YEAR BETWEEN 1971 AND 1991) MATCH_RECOGNIZE ( ORDER BY YEAR MEASURES MATCH_NUMBER() MATCH#, CLASSIFIER() CLS ALL ROWS PER MATCH AFTER MATCH SKIP PAST LAST ROW PATTERN (A SAME* DIFF+ LIKE_FIRST+) DEFINE SAME AS WINNER = PREV(WINNER), DIFF AS WINNER != A.WINNER, LIKE_FIRST AS WINNER = A.WINNER ) ORDER BY YEAR;
  • 43. This presentation is available in http://db-oriented.com/presentations © Oren Nakdimon © Oren Nakdimon SELECT MATCH#, YEAR, WINNER, SONG, POINTS, VAR FROM (SELECT * FROM EUROVISION_WINNERS WHERE YEAR BETWEEN 1971 AND 1991) MATCH_RECOGNIZE ( ORDER BY YEAR MEASURES MATCH_NUMBER() MATCH#, CLASSIFIER() VAR ALL ROWS PER MATCH AFTER MATCH SKIP PAST LAST ROW PATTERN (A SAME* DIFF+ LIKE_FIRST+) DEFINE SAME AS WINNER = PREV(WINNER), DIFF AS WINNER != A.WINNER, LIKE_FIRST AS WINNER = A.WINNER ) ORDER BY YEAR;
  • 44. This presentation is available in http://db-oriented.com/presentations © Oren Nakdimon © Oren Nakdimon SELECT MATCH#, YEAR, WINNER, SONG, POINTS, VAR FROM (SELECT * FROM EUROVISION_WINNERS WHERE YEAR BETWEEN 1971 AND 1991) MATCH_RECOGNIZE ( ORDER BY YEAR MEASURES MATCH_NUMBER() MATCH#, CLASSIFIER() VAR ALL ROWS PER MATCH WITH UNMATCHED ROWS AFTER MATCH SKIP PAST LAST ROW PATTERN (A SAME* DIFF+ LIKE_FIRST+) DEFINE SAME AS WINNER = PREV(WINNER), DIFF AS WINNER != A.WINNER, LIKE_FIRST AS WINNER = A.WINNER ) ORDER BY YEAR;
  • 45. This presentation is available in http://db-oriented.com/presentations © Oren Nakdimon © Oren Nakdimon SELECT MATCH#, YEAR, WINNER, SONG, POINTS, VAR FROM (SELECT * FROM EUROVISION_WINNERS WHERE YEAR BETWEEN 1971 AND 1991) MATCH_RECOGNIZE ( ORDER BY YEAR MEASURES MATCH_NUMBER() MATCH#, CLASSIFIER() VAR ALL ROWS PER MATCH WITH UNMATCHED ROWS AFTER MATCH SKIP PAST LAST ROW PATTERN (A SAME* DIFF+ LIKE_FIRST+) DEFINE SAME AS WINNER = PREV(WINNER), DIFF AS WINNER != A.WINNER, LIKE_FIRST AS WINNER = A.WINNER ) ORDER BY YEAR; PAST LAST ROW (the default) TO NEXT ROW TO FIRST var TO [LAST] var
  • 46. This presentation is available in http://db-oriented.com/presentations © Oren Nakdimon © Oren Nakdimon SELECT MATCH#, YEAR, WINNER, SONG, POINTS, VAR FROM (SELECT * FROM EUROVISION_WINNERS WHERE YEAR BETWEEN 1971 AND 1991) MATCH_RECOGNIZE ( ORDER BY YEAR MEASURES MATCH_NUMBER() MATCH#, CLASSIFIER() VAR ALL ROWS PER MATCH WITH UNMATCHED ROWS AFTER MATCH SKIP TO FIRST DIFF PATTERN (A SAME* DIFF+ LIKE_FIRST+) DEFINE SAME AS WINNER = PREV(WINNER), DIFF AS WINNER != A.WINNER, LIKE_FIRST AS WINNER = A.WINNER ) ORDER BY MATCH#, YEAR;
  • 47. This presentation is available in http://db-oriented.com/presentations © Oren Nakdimon © Oren Nakdimon SELECT MATCH#, YEAR, WINNER, SONG, POINTS, VAR FROM (SELECT * FROM EUROVISION_WINNERS WHERE YEAR BETWEEN 1971 AND 1991) MATCH_RECOGNIZE ( ORDER BY YEAR MEASURES MATCH_NUMBER() MATCH#, CLASSIFIER() VAR ALL ROWS PER MATCH WITH UNMATCHED ROWS AFTER MATCH SKIP TO FIRST DIFF PATTERN (A SAME* DIFF+ LIKE_FIRST+) DEFINE SAME AS WINNER = PREV(WINNER), DIFF AS WINNER != A.WINNER, LIKE_FIRST AS WINNER = A.WINNER ) ORDER BY MATCH#, YEAR; FROM_YEAR TO_YEAR 9 NON_WINNING_YEARS WINNER
  • 48. This presentation is available in http://db-oriented.com/presentations © Oren Nakdimon © Oren Nakdimon FROM_YEAR TO_YEAR 9 WINNER SELECT MATCH#, WINNER, FROM_YEAR, TO_YEAR, NON_WINNER_YEARS FROM (SELECT * FROM EUROVISION_WINNERS WHERE YEAR BETWEEN 1971 AND 1991) MATCH_RECOGNIZE ( ORDER BY YEAR MEASURES MATCH_NUMBER() MATCH#, A.WINNER WINNER, FIRST(YEAR) FROM_YEAR, LAST(YEAR) TO_YEAR, COUNT(DIFF.*) NON_WINNER_YEARS ONE ROW PER MATCH AFTER MATCH SKIP TO FIRST DIFF PATTERN (A SAME* DIFF+ LIKE_FIRST+) DEFINE SAME AS WINNER = PREV(WINNER), DIFF AS WINNER != A.WINNER, LIKE_FIRST AS WINNER = A.WINNER ) ORDER BY MATCH#; NON_WINNING_YEARS
  • 49. This presentation is available in http://db-oriented.com/presentations © Oren Nakdimon © Oren Nakdimon FROM_YEAR TO_YEAR 9 WINNER SELECT MATCH#, WINNER, FROM_YEAR, TO_YEAR, NON_WINNER_YEARS FROM (SELECT * FROM EUROVISION_WINNERS WHERE YEAR BETWEEN 1971 AND 1991) MATCH_RECOGNIZE ( ORDER BY YEAR MEASURES MATCH_NUMBER() MATCH#, A.WINNER WINNER, FIRST(YEAR) FROM_YEAR, LAST(YEAR) TO_YEAR, COUNT(DIFF.*) NON_WINNER_YEARS ONE ROW PER MATCH AFTER MATCH SKIP TO FIRST DIFF PATTERN (A SAME* DIFF+ LIKE_FIRST+) DEFINE SAME AS WINNER = PREV(WINNER), DIFF AS WINNER != A.WINNER, LIKE_FIRST AS WINNER = A.WINNER ) ORDER BY MATCH#; NON_WINNING_YEARS
  • 50. This presentation is available in http://db-oriented.com/presentations © Oren Nakdimon © Oren Nakdimon FROM_YEAR TO_YEAR 9 WINNER SELECT MATCH#, WINNER, FROM_YEAR, TO_YEAR, NON_WINNER_YEARS FROM (SELECT * FROM EUROVISION_WINNERS WHERE YEAR BETWEEN 1971 AND 1991) MATCH_RECOGNIZE ( ORDER BY YEAR MEASURES MATCH_NUMBER() MATCH#, A.WINNER WINNER, FIRST(YEAR) FROM_YEAR, LAST(YEAR) TO_YEAR, COUNT(DIFF.*) NON_WINNER_YEARS ONE ROW PER MATCH AFTER MATCH SKIP TO FIRST DIFF PATTERN (A SAME* DIFF+ LIKE_FIRST+) DEFINE SAME AS WINNER = PREV(WINNER), DIFF AS WINNER != A.WINNER, LIKE_FIRST AS WINNER = A.WINNER ) ORDER BY MATCH#; NON_WINNING_YEARS
  • 51. This presentation is available in http://db-oriented.com/presentations © Oren Nakdimon © Oren Nakdimon FROM_YEAR TO_YEAR 9 WINNER SELECT MATCH#, WINNER, FROM_YEAR, TO_YEAR, NON_WINNER_YEARS FROM (SELECT * FROM EUROVISION_WINNERS WHERE YEAR BETWEEN 1971 AND 1991) MATCH_RECOGNIZE ( ORDER BY YEAR MEASURES MATCH_NUMBER() MATCH#, A.WINNER WINNER, FIRST(YEAR) FROM_YEAR, LAST (YEAR) TO_YEAR, COUNT(DIFF.*) NON_WINNER_YEARS ONE ROW PER MATCH AFTER MATCH SKIP TO FIRST DIFF PATTERN (A SAME* DIFF+ LIKE_FIRST+) DEFINE SAME AS WINNER = PREV(WINNER), DIFF AS WINNER != A.WINNER, LIKE_FIRST AS WINNER = A.WINNER ) ORDER BY MATCH#; NON_WINNING_YEARS
  • 52. This presentation is available in http://db-oriented.com/presentations © Oren Nakdimon © Oren Nakdimon FROM_YEAR TO_YEAR 9 WINNER SELECT MATCH#, WINNER, FROM_YEAR, TO_YEAR, NON_WINNER_YEARS FROM (SELECT * FROM EUROVISION_WINNERS WHERE YEAR BETWEEN 1971 AND 1991) MATCH_RECOGNIZE ( ORDER BY YEAR MEASURES MATCH_NUMBER() MATCH#, A.WINNER WINNER, FIRST(YEAR) FROM_YEAR, LAST (YEAR) TO_YEAR, COUNT(DIFF.*) NON_WINNER_YEARS ONE ROW PER MATCH AFTER MATCH SKIP TO FIRST DIFF PATTERN (A SAME* DIFF+ LIKE_FIRST+) DEFINE SAME AS WINNER = PREV(WINNER), DIFF AS WINNER != A.WINNER, LIKE_FIRST AS WINNER = A.WINNER ) ORDER BY MATCH#; NON_WINNING_YEARS COUNT MAX MIN SUM AVG
  • 53. This presentation is available in http://db-oriented.com/presentations © Oren Nakdimon © Oren Nakdimon FROM_YEAR TO_YEAR 9 WINNER SELECT MATCH#, WINNER, FROM_YEAR, TO_YEAR, NON_WINNER_YEARS FROM (SELECT * FROM EUROVISION_WINNERS WHERE YEAR BETWEEN 1971 AND 1991) MATCH_RECOGNIZE ( ORDER BY YEAR MEASURES MATCH_NUMBER() MATCH#, A.WINNER WINNER, FIRST(YEAR) FROM_YEAR, LAST (YEAR) TO_YEAR, COUNT(DIFF.*) NON_WINNER_YEARS ONE ROW PER MATCH AFTER MATCH SKIP TO FIRST DIFF PATTERN (A SAME* DIFF+ LIKE_FIRST+) DEFINE SAME AS WINNER = PREV(WINNER), DIFF AS WINNER != A.WINNER, LIKE_FIRST AS WINNER = A.WINNER ) ORDER BY MATCH#; NON_WINNING_YEARS
  • 54. This presentation is available in http://db-oriented.com/presentations © Oren Nakdimon © Oren Nakdimon FROM_YEAR TO_YEAR 9 WINNER NON_WINNING_YEARS SELECT MATCH#, WINNER, FROM_YEAR, TO_YEAR, NON_WINNER_YEARS FROM (SELECT * FROM EUROVISION_WINNERS WHERE YEAR BETWEEN 1971 AND 1991) MATCH_RECOGNIZE ( ORDER BY YEAR MEASURES MATCH_NUMBER() MATCH#, A.WINNER WINNER, FIRST(YEAR) FROM_YEAR, LAST (YEAR) TO_YEAR, COUNT(DIFF.*) NON_WINNER_YEARS ONE ROW PER MATCH AFTER MATCH SKIP TO FIRST DIFF PATTERN (A SAME* DIFF+ LIKE_FIRST+) DEFINE SAME AS WINNER = PREV(WINNER), DIFF AS WINNER != A.WINNER, LIKE_FIRST AS WINNER = A.WINNER ) ORDER BY MATCH#;
  • 55. This presentation is available in http://db-oriented.com/presentations © Oren Nakdimon © Oren Nakdimon 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)) );
  • 56. This presentation is available in http://db-oriented.com/presentations © Oren Nakdimon © Oren Nakdimon 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)) );
  • 57. This presentation is available in http://db-oriented.com/presentations © Oren Nakdimon © Oren Nakdimon 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)) );
  • 58. This presentation is available in http://db-oriented.com/presentations © Oren Nakdimon © Oren Nakdimon 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)) );
  • 59. This presentation is available in http://db-oriented.com/presentations © Oren Nakdimon © Oren Nakdimon 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)) ); NF                Implicit Pattern Variable
  • 60. This presentation is available in http://db-oriented.com/presentations © Oren Nakdimon © Oren Nakdimon 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 NF                Implicit Pattern Variable
  • 61. This presentation is available in http://db-oriented.com/presentations © Oren Nakdimon © Oren Nakdimon 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 Grouping NF                Implicit Pattern Variable
  • 62. This presentation is available in http://db-oriented.com/presentations © Oren Nakdimon © Oren Nakdimon 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)) ); NF                Implicit Pattern Variable
  • 63. This presentation is available in http://db-oriented.com/presentations © Oren Nakdimon © Oren Nakdimon Fibonacci Numbers 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)) );
  • 64. This presentation is available in http://db-oriented.com/presentations © Oren Nakdimon © Oren Nakdimon Fibonacci Numbers 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
  • 65. This presentation is available in http://db-oriented.com/presentations © Oren Nakdimon © Oren Nakdimon Fibonacci Numbers 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)) );
  • 66. This presentation is available in http://db-oriented.com/presentations © Oren Nakdimon © Oren Nakdimon Additional Resources  The Documentation: https://docs.oracle.com/en/database/oracle/oracle- database/18/dwhsg/sql-pattern-matching-data-warehouses.html  Keith Laker’s blog: https://oracle-big-data.blogspot.com/  Stew Ashton’s blog: https://stewashton.wordpress.com/category/match_recognize/
  • 67. THANK YOU Oren Nakdimon www.db-oriented.com  oren@db-oriented.com  +972-54-4393763 @DBoriented