SlideShare a Scribd company logo
1
2
22
2
3
4
centralised
backed up
secure
5
job done ?
6
6 months later
7
8
9
10
11
12
McDonald's Conjecture
on Large Corporations:
14
"you cannot kill Excel"
15
16
custom queries
adhoc reports
17
18
19
20
you cannot kill Excel
21
"why?"
22
23
24
formulas
inter-row calculations
familiar excel expressions
25
compare traditional
26
design,
document,
signoff,
PLSQL,
develop,
test,
implement
27
28
you
cannot
kill
Excel
29
30
formulas
inter-row calculations
familiar excel expressions
...all in SQL
31
"end user metaphor"
32
33
model clause replicates this
34
my first MODEL query
35
SQL> select year
2 ,ver
3 ,bugs
4 from versions
5 where platform = 'Win';
YEAR VER BUGS
---------- --------------- ----------
1995 Windows95 100
1998 Windows98 130
2000 WindowsME 170
2002 WindowsXP 140
36
SQL> select year
2 ,ver
3 ,bugs
4 from versions
5 where platform = 'Win';
YEAR VER BUGS
---------- --------------- ----------
1995 Windows95 100
1998 Windows98 130
2000 WindowsME 170
2002 WindowsXP 140
37
excel = MODEL
38
SQL> select year
2 ,ver
3 ,bugs
4 from versions
5 where platform = 'Win'
6 model
7 dimension by (year)
8 measures (ver,bugs)
9 rules
10 ()
11 /
YEAR VER BUGS
---------- --------------- ----------
1995 Windows95 100
1998 Windows98 130
2000 WindowsME 170
2002 WindowsXP 140
39
paid by line of code ...
40
SQL> select year
2 ,ver
3 ,bugs
4 from versions
5 where platform = 'Win'
6 model
7 dimension by (year)
8 measures (ver,bugs)
9 rules
10 ()
11 /
41
dimensions
42
dimension
43
SQL> select year
2 ,ver
3 ,bugs
4 from versions
5 where platform = 'Win'
6 model
7 dimension by (year)
8 measures (ver,bugs)
9 rules
10 ()
11 /
44
measures
45
dimension
measures
46
SQL> select year
2 ,ver
3 ,bugs
4 from versions
5 where platform = 'Win'
6 model
7 dimension by (year)
8 measures (ver,bugs)
9 rules
10 ()
11 /
47
rules
defined by dimension,
impact measures
48
SQL> select year
2 ,ver
3 ,bugs
4 from versions
5 where platform = 'Win'
6 model
7 dimension by (year)
8 measures (ver,bugs)
9 rules
10 ( ver[2009]='Windows7',
11 bugs[2009]=150 );
49
SQL> select year
2 ,ver
3 ,bugs
4 from versions
5 where platform = 'Win'
6 model
7 dimension by (year)
8 measures (ver,bugs)
9 rules
10 ( ver[2009]='Windows7',
11 bugs[2009]=150 );
50
SQL> select year
2 ,ver
3 ,bugs
4 from versions
5 where platform = 'Win'
6 model
7 dimension by (year)
8 measures (ver,bugs)
9 rules
10 ( ver[2009]='Windows7',
11 bugs[2009]=150 );
51
SQL> select year
2 ,ver
3 ,bugs
4 from versions
5 where platform = 'Win'
6 model
7 dimension by (year)
8 measures (ver,bugs)
9 rules
10 ( ver[2009]='Windows7',
11 bugs[2009]=150
12 )
13 /
YEAR VER BUGS
---------- --------------- ----------
1995 Windows95 100
1998 Windows98 130
2000 WindowsME 170
2002 WindowsXP 140
2009 Windows7 150
52
relational data
dimensioned array
relational data
53
you'll still need "Excel"
Discoverer
APEX
Crystal Reports
54
a closer look
55
too very flexible
56
57
create measures
58
SQL> select year
2 ,ver
3 ,bugs
4 ,est_bugs
5 from versions
6 where platform = 'Win'
7 model
8 dimension by (year)
9 measures (ver,bugs, 0 est_bugs)
10 rules sequential order
11 ( est_bugs[1995]=100 )
12 order by year;
YEAR VER BUGS EST_BUGS
---------- --------------- ---------- ----------
1995 Windows95 100 100
1998 Windows98 130 0
2000 WindowsME 170 0
2002 WindowsXP 140 0
59
60
SQL> select year
2 ,ver
3 ,bugs
4 ,est_bugs
5 from versions
6 where platform = 'Win'
7 model
8 dimension by (year)
9 measures (ver,bugs, 0 est_bugs)
10 rules sequential order
11 (
12 est_bugs[1995]=100 ,
13 est_bugs[1998]=100 ,
14 est_bugs[2000]=100 ,
15 est_bugs[2002]=100
16 ...
61
SQL> select year
2 ,ver
3 ,bugs
4 ,est_bugs
5 from versions
6 where platform = 'Win'
7 model
8 dimension by (year)
9 measures (ver,bugs, 0 est_bugs)
10 rules sequential order
11 (
12 est_bugs[ANY]=100
13 );
YEAR VER BUGS EST_BUGS
---------- --------------- ---------- ----------
1995 Windows95 100 100
1998 Windows98 130 100
2000 WindowsME 170 100
2002 WindowsXP 140 100
62
63
SQL> select year
2 ,ver
3 ,bugs
4 ,est_bugs
5 from versions
6 where platform = 'Win'
7 model
8 dimension by (year)
9 measures (ver,bugs, 0 est_bugs)
10 rules sequential order
11 ( est_bugs[1995]=bugs[1995]*1.1 )
12 order by year;
YEAR VER BUGS EST_BUGS
---------- --------------- ---------- ----------
1995 Windows95 100 110
1998 Windows98 130 0
2000 WindowsME 170 0
2002 WindowsXP 140 0
64
65
back reference
66
SQL> select year
2 ,ver
3 ,bugs
4 ,est_bugs
5 from versions
6 where platform = 'Win'
7 model
8 dimension by (year)
9 measures (ver,bugs, 0 est_bugs)
10 rules
11 ( est_bugs[ANY]=bugs[CV()]*1.1
12 )
13 /
YEAR VER BUGS EST_BUGS
---------- --------------- ---------- ----------
1995 Windows95 100 110
1998 Windows98 130 143
2000 WindowsME 170 187
2002 WindowsXP 140 154
67
multiple dimensions
68
69
SQL> select year
2 ,ver
3 ,bugs
4 ,est_bugs
5 from versions
6 where platform = 'Win'
7 model
8 dimension by (department, year)
9 measures (ver,bugs, 0 est_bugs)
10 rules
11 ( est_bugs['HR', ANY]=bugs['HR', CV()]*1.1
12 ( est_bugs['Sales', ANY]=bugs['Sales', CV()]*1.2
13 ( est_bugs['Payroll', ANY]=bugs['Payroll', CV()]*1.5
14 )
15 /
not just numeric
70
71
dimensions define a cell
72
SQL> select year
2 ,ver
3 ,bugs
4 ,est_bugs
5 from versions
6 model
7 dimension by (year)
8 measures (ver,bugs, 0 est_bugs)
9 rules
10 (
11 );
YR VER BUGS EST_BUGS
---------- --------------- ---------- ----------
1995 Windows95 100 0
1998 Windows98 130 0
2000 WindowsME 170 0
2002 WindowsXP 140 0
1996 RedHat 50 0
2006 Oracle 80 0
2001 SUSE 65 0
2003 CentOS 90 0
73
SQL> insert into versions
2 values ('Linux',2001,'Fedora',70);
1 row created.
SQL> select yr
2 ,ver
3 ,bugs
4 ,est_bugs
5 from versions
6 model
7 dimension by (year as yr)
8 measures (ver,bugs, 0 est_bugs)
9 rules
10 (
11 );
from versions
*
ERROR at line 5:
ORA-32638: Non unique addressing in MODEL dimensions
74
75
SQL> select yr
2 ,ver
3 ,bugs
4 ,est_bugs
5 from versions
6 model UNIQUE SINGLE REFERENCE
7 dimension by (year as yr)
8 measures (ver,bugs, 0 est_bugs)
9 rules ( );
YR VER BUGS EST_BUGS
---------- --------------- ---------- ----------
1995 Windows95 100 0
1998 Windows98 130 0
2000 WindowsME 170 0
2002 WindowsXP 140 0
1996 RedHat 50 0
2006 Oracle 80 0
2001 SUSE 65 0
2003 CentOS 90 0
2001 Fedora 70 0
76
unique single reference
rules cannot cross dimensions
77
dimensions can be null
78
SQL> select yr,ver,bugs,est_bugs
2 from versions
3 where platform = 'Win'
4 model
5 dimension by (year as yr)
6 measures (ver,bugs, 0 est_bugs)
7 rules
8 (
9 est_bugs[null]=140
10 );
YR VER BUGS EST_BUGS
---------- --------------- ---------- ----------
1995 Windows95 100 0
1998 Windows98 130 0
2000 WindowsME 170 0
2002 WindowsXP 140 0
(null) 140
79
idiosyncracies # 1
80
SQL> select year as yr
2 ,ver
3 ,bugs
4 ,est_bugs
5 from versions
6 model
7 dimension by (yr)
8 measures (ver,bugs, 0 est_bugs)
9 rules
10 (
11 );
dimension by (yr)
*
ERROR at line 7:
ORA-00904: "YR": invalid identifier
81
SQL> select yr
2 ,ver
3 ,bugs
4 ,est_bugs
5 from versions
6 model
7 dimension by (year as yr)
8 measures (ver,bugs, 0 est_bugs)
9 rules
10 (
11 );
YR VER BUGS EST_BUGS
---------- --------------- ---------- ----------
1995 Windows95 100 0
1998 Windows98 130 0
2000 WindowsME 170 0
2002 WindowsXP 140 0
1996 RedHat 50 0
2006 Oracle 80 0
2001 SUSE 65 0
2003 CentOS 90 0
82
more on measures
83
any standard expression
84
SQL> select ...
7 model
8 dimension by (year)
9 measures (ver,
10 bugs,
11 bugs*0.5 half_bugs,
12 avg(bugs) over (
13 order by year rows
14 between 1 preceding
15 and 1 following ) est_bugs)
16 rules
17 (
18 );
YEAR VER BUGS HALF_BUGS EST_BUGS
---------- ------------ ---------- ---------- ----------
1995 Windows95 100 50 115
1998 Windows98 130 65 133.333333
2000 WindowsME 170 85 146.666667
2002 WindowsXP 140 70 155
85
aggregates
86
SQL> select platform, tot_bugs
2 from versions
3 group by platform
4 model
5 dimension by (platform)
6 measures (sum(bugs) as tot_bugs)
7 rules
8 (
9 );
PLATFORM TOT_BUGS
---------- ----------
Linux 285
Win 540
87
idiosyncracy # 2
88
SQL> select platform, sum(bugs) as tot_bugs
2 from versions
3 group by platform
4 model
5 dimension by (platform)
6 measures (tot_bugs)
7 rules
8 (
9 );
measures (tot_bugs)
*
ERROR at line 6:
ORA-00904: "TOT_BUGS": invalid identifier
89
idiosyncracies # 3
90
SQL> select platform, year, ver, bugs
2 from versions
3 where platform = 'Win'
4 model
5 dimension by (year)
6 measures (ver,bugs)
7 rules
8 ( ver[2009]='Windows7',
9 bugs[2009]=150
10 );
select platform, year, ver, bugs
*
ERROR at line 1:
ORA-32614: illegal MODEL SELECT expression
91
SQL> select platform, year, ver, bugs
2 from versions
3 where platform = 'Win'
4 model
5 dimension by (year)
6 measures (ver,bugs,platform)
7 rules
8 ( ver[2009]='Windows7',
9 bugs[2009]=150
10 );
PLATFORM YEAR VER BUGS
---------- ---------- --------------- ----------
Win 1995 Windows95 100
Win 1998 Windows98 130
Win 2000 WindowsME 170
Win 2002 WindowsXP 140
2009 Windows7 150
92
idiosyncracies # 4
93
SQL> select year, ver, bugs
2 from versions
3 where platform = 'Win'
4 model
5 dimension by (year)
6 measures (ver,bugs,year)
7 rules
8 ( ver[2009]='Windows7',
9 bugs[2009]=150,
10 year[2009]=2010
11 );
select year, ver, bugs
*
ERROR at line 1:
ORA-00957: duplicate column name
94
SQL> select year, ver, bugs
2 from versions
3 where platform = 'Win'
4 model
5 dimension by (year)
6 measures (ver,bugs,year next_year)
7 rules
8 ( ver[2009]='Windows7',
9 bugs[2009]=150,
10 next_year[2009]=2010
11 );
YEAR VER BUGS
---------- --------------- ----------
1995 Windows95 100
1998 Windows98 130
2000 WindowsME 170
2002 WindowsXP 140
2009 Windows7 150
95
SQL> select year, ver, bugs, next_year
2 from versions
3 where platform = 'Win'
4 model
5 dimension by (year)
6 measures (ver,bugs,year next_year)
7 rules
8 ( ver[2009]='Windows7',
9 bugs[2009]=150,
10 next_year[2009]=2010
11 );
YEAR VER BUGS NEXT_YEAR
---------- --------------- ---------- ----------
1995 Windows95 100 1995
1998 Windows98 130 1998
2000 WindowsME 170 2000
2002 WindowsXP 140 2002
2009 Windows7 150 2010
96
idiosyncracies # 5
97
SQL> select year, ver, bugs
2 from versions
3 where platform = 'Win'
4 model
5 dimension by (year)
6 measures (ver,bugs,null est_sales)
7 rules
8 (
9 est_sales[ANY]=0
10 );
measures (ver,bugs,null est_sales)
*
ERROR at line 6:
ORA-01723: zero-length columns are not allowed
98
SQL> select year, ver, bugs
2 from versions
3 where platform = 'Win'
4 model
5 dimension by (year)
6 measures (ver,bugs,to_number(null) est_sales)
7 rules
8 (
9 est_sales[ANY]=0
10 );
YEAR VER BUGS
---------- --------------- ----------
1995 Windows95 100
1998 Windows98 130
2000 WindowsME 170
2002 WindowsXP 140
99
SQL> select year, ver, bugs, sales_rep
2 from versions
3 where platform = 'Win'
4 model
5 dimension by (year)
6 measures (ver,bugs,
7 cast(null as varchar2(20)) sales_rep)
8 rules
9 (
10 sales_rep[2000]='Mike'
11 );
YEAR VER BUGS SALES_REP
---------- --------------- ---------- --------------------
1995 Windows95 100
1998 Windows98 130
2002 WindowsXP 140
2000 WindowsME 170 Mike
100
SQL> select year, ver, bugs, sales_rep
2 from versions
3 where platform = 'Win'
4 model
5 dimension by (year)
6 measures (ver,bugs,'Unknown' sales_rep)
7 rules
8 (
9 sales_rep[2000]='Mike Jones'
10 );
ERROR:
ORA-25137: Data value out of range
101
SQL> select year, ver, bugs, sales_rep
2 from versions
3 where platform = 'Win'
4 model
5 dimension by (year)
6 measures (ver,bugs,
7 cast('Unknown' as varchar2(20)) sales_rep)
8 rules
9 (
10 sales_rep[2000]='Mike Jones'
11 );
YEAR VER BUGS SALES_REP
---------- --------------- ---------- --------------------
1995 Windows95 100 Unknown
1998 Windows98 130 Unknown
2002 WindowsXP 140 Unknown
2000 WindowsME 170 Mike Jones
102
partitions
103
104
SQL> select platform
...
6 from versions
7 model
8 partition by ( platform )
9 dimension by (year)
10 measures (ver,bugs, 0 est_bugs)
11 rules
12 ( est_bugs[1995]=bugs[1995],
13 est_bugs[year > 1995]=bugs[CV()]*1.1
14 );
PLATFORM YEAR VER BUGS EST_BUGS
---------- ---------- --------------- ---------- ----------
Linux 1996 RedHat 50 55
Linux 2006 Oracle 80 88
Linux 2001 SUSE 65 71.5
Linux 2003 CentOS 90 99
Linux 1995
Win 1995 Windows95 100 100
Win 1998 Windows98 130 143
Win 2000 WindowsME 170 187
Win 2002 WindowsXP 140 154
105
rules applied per partition
106
rules
107
standard expressions
108
SQL> select yr
2 ,ver
3 ,bugs
4 ,est_bugs
5 from versions
6 where platform = 'Win'
7 model
8 dimension by (year as yr)
9 measures (ver,bugs, 0 est_bugs)
10 rules
11 (
12 est_bugs[1998]=100,
13 bugs[2000]= :bindvar,
14 est_bugs[2009]= dbms_random.value(80,100)
15 );
YR VER BUGS EST_BUGS
---------- ------------ ---------- ----------
1995 Windows95 100 0
2002 WindowsXP 140 0
1998 Windows98 130 100
2000 WindowsME <:bv> 0
2009 90.1501647
109
"no" subqueries
110
SQL> select yr
2 ,ver
3 ,bugs
4 ,est_bugs
5 from versions
6 where platform = 'Win'
7 model
8 dimension by (year as yr)
9 measures (ver,bugs, 0 est_bugs)
10 rules
11 (
12 est_bugs[2009]=
13 ( select max(bugs) from versions )
14 );
select yr
*
ERROR at line 1:
ORA-32620: illegal subquery within MODEL rules
111
SQL> select yr
2 ,ver
3 ,bugs
4 ,est_bugs
5 from versions
6 where platform = 'Win'
7 model
8 dimension by (year as yr)
9 measures (ver,bugs, 0 est_bugs,
10 ( select max(bugs) from versions ) x)
11 rules
12 (
13 est_bugs[2009]= x[2000]
14 );
YR VER BUGS EST_BUGS
---------- ------------ ---------- ----------
1995 Windows95 100 0
1998 Windows98 130 0
2002 WindowsXP 140 0
2000 WindowsME 170 0
2009 170
112
CV( )
113
SQL> select year
2 ,ver
3 ,bugs
4 ,est_bugs
5 from versions
6 where platform = 'Win'
7 model
8 dimension by (year)
9 measures (ver,bugs, 0 est_bugs)
10 rules
11 ( est_bugs[ANY]=bugs[CV()]*1.1
12 )
13 /
YEAR VER BUGS EST_BUGS
---------- --------------- ---------- ----------
1995 Windows95 100 110
1998 Windows98 130 143
2000 WindowsME 170 187
2002 WindowsXP 140 154
114
SQL> select year
2 ,ver
3 ,bugs
4 ,est_bugs
5 from versions
6 where platform = 'Win'
7 model
8 dimension by (year)
9 measures (ver,bugs, 0 est_bugs, 0 zero_bug)
10 rules
11 ( zero_bug[ANY]=CV()+10
12 );
( zero_bug[ANY]=CV()+10
*
ERROR at line 11:
ORA-32611: incorrect use of MODEL CV operator
115
SQL> select year
2 ,ver
3 ,bugs
4 ,est_bugs
5 ,zero_bug
6 from versions
7 where platform = 'Win'
8 model
9 dimension by (year)
10 measures (ver,bugs, 0 est_bugs, 0 zero_bug)
11 rules
12 ( zero_bug[ANY]=CV(YEAR)+10
13 );
YEAR VER BUGS EST_BUGS ZERO_BUG
---------- ------------ ---------- ---------- ----------
1995 Windows95 100 0 2005
1998 Windows98 130 0 2008
2000 WindowsME 170 0 2010
2002 WindowsXP 140 0 2012
116
cross-row rules
117
SQL> select fib
2 from ( select rownum r from dual
3 connect by level <= 10 )
4 model
5 dimension by (r)
6 measures (0 fib)
7 rules
8 ( fib[1]=1,
9 fib[2]=1,
10 fib[r>2]=fib[CV()-1]+fib[CV()-2] );
FIB
----------
1
1
2
3
5
8
13
21
34
55
118
key point
119
symbolic versus positional
120
SQL> select yr
2 ,ver
3 ,bugs
4 ,est_bugs
5 from versions
6 where platform = 'Win'
7 model
8 dimension by (year as yr)
9 measures (ver,bugs, 0 est_bugs)
10 rules
11 (
12 est_bugs[2009]=100,
13 ver[2009]='Windows7'
14 );
YR VER BUGS EST_BUGS
---------- ------------ ---------- ----------
1995 Windows95 100 0
1998 Windows98 130 0
2000 WindowsME 170 0
2002 WindowsXP 140 0
2009 Windows7 100
update or create a
dimension value of '2009'
121
SQL> select yr
2 ,ver
3 ,bugs
4 ,est_bugs
5 from versions
6 where platform = 'Win'
7 model
8 dimension by (year as yr)
9 measures (ver,bugs, 0 est_bugs)
10 rules
11 (
12 est_bugs[yr=2009]=100,
13 ver[yr=2009]='Windows7'
14 );
YR VER BUGS EST_BUGS
---------- ------------ ---------- ----------
1995 Windows95 100 0
1998 Windows98 130 0
2000 WindowsME 170 0
2002 WindowsXP 140 0
update if exists a
dimension value of '2009'
122
FOR
123
SQL> select yr
2 ,ver
3 ,bugs
4 ,est_bugs
5 from versions
6 where platform = 'Win'
7 model
8 dimension by (year as yr)
9 measures (ver,bugs, 0 est_bugs)
10 rules
11 (
12 est_bugs[yr IN (2000,2009)]=100
13 );
YR VER BUGS EST_BUGS
---------- ------------ ---------- ----------
1995 Windows95 100 0
1998 Windows98 130 0
2002 WindowsXP 140 0
2000 WindowsME 170 100
124
SQL> select yr
2 ,ver
3 ,bugs
4 ,est_bugs
5 from versions
6 where platform = 'Win'
7 model
8 dimension by (year as yr)
9 measures (ver,bugs, 0 est_bugs)
10 rules
11 (
12 est_bugs[FOR yr IN (2000,2009)]=100
13 );
YR VER BUGS EST_BUGS
---------- ------------ ---------- ----------
1995 Windows95 100 0
1998 Windows98 130 0
2002 WindowsXP 140 0
2000 WindowsME 170 100
2009 100
125
SQL> select yr
2 ,ver
3 ,bugs
4 ,est_bugs
5 from versions
6 where platform = 'Win'
7 model
8 dimension by (year as yr)
9 measures (ver,bugs, 0 est_bugs)
10 rules
11 (
12 est_bugs[FOR yr FROM 2002 TO 2005 INCREMENT 1]=100
13 );
YR VER BUGS EST_BUGS
---------- ------------ ---------- ----------
1995 Windows95 100 0
1998 Windows98 130 0
2000 WindowsME 170 0
2002 WindowsXP 140 100
2003 100
2004 100
2005 100
126
SQL> select ...
7 model
8 dimension by (year as yr)
9 measures (ver,bugs, 0 est_bugs)
10 rules
11 (
12 est_bugs[FOR yr IN
13 ( select year
14 from versions
15 where platform = 'Linux') ]=100
16 );
YR VER BUGS EST_BUGS
---------- ------------ ---------- ----------
1995 Windows95 100 0
1998 Windows98 130 0
2000 WindowsME 170 0
2002 WindowsXP 140 0
1996 100
2006 100
2001 100
2003 100
127
update vs upsert
128
SQL> select yr
2 ,ver
3 ,bugs
4 ,est_bugs
5 from versions
6 where platform = 'Win'
7 model
8 dimension by (year as yr)
9 measures (ver,bugs, 0 est_bugs)
10 rules
11 (
12 est_bugs[FOR yr IN (2000,2009)]=100,
13 ver[2009]='Windows7' );
YR VER BUGS EST_BUGS
---------- ------------ ---------- ----------
1995 Windows95 100 0
1998 Windows98 130 0
2002 WindowsXP 140 0
2000 WindowsME 170 100
2009 Windows7 100
UPSERT
129
SQL> select yr
2 ,ver
3 ,bugs
4 ,est_bugs
5 from versions
6 where platform = 'Win'
7 model
8 dimension by (year as yr)
9 measures (ver,bugs, 0 est_bugs)
10 rules UPDATE
11 (
12 est_bugs[FOR yr IN (2000,2009)]=100,
13 ver[2009]='Windows7' );
YR VER BUGS EST_BUGS
---------- ------------ ---------- ----------
1995 Windows95 100 0
1998 Windows98 130 0
2002 WindowsXP 140 0
2000 WindowsME 170 100
2009 Windows7 100
2009 gone
130
idiosyncracies # 2
the "sert" in upsert
131
SQL> select *
2 from versions
3 where platform = 'z/OS';
no rows selected
SQL> select *
2 from versions
3 where platform = 'z/OS'
4 model
5 dimension by (year as yr)
6 measures (ver, 0 est_bugs)
7 rules
8 ( est_bugs[FOR yr IN (2000,2002,2009)]=100,
9 ver[ANY]='IBM' );
YR VER EST_BUGS
---------- --------------- ----------
2000 IBM 100
2002 IBM 100
2009 IBM 100
132
note: simplification
upsert
upsert all
update
133
nested references
134
SQL> select yr
2 ,ver
3 ,bugs
4 ,est_bugs
5 from versions
6 where platform = 'Win'
7 model
8 dimension by (year as yr)
9 measures (ver,bugs, 0 est_bugs, year as yr2)
10 rules
11 (
12 yr2[ANY]=yr2[CV()]-2,
13 est_bugs[yr2[2000]]=100
14 );
YR VER BUGS EST_BUGS
---------- ------------ ---------- ----------
1995 Windows95 100 0
1998 Windows98 130 100
2000 WindowsME 170 0
2002 WindowsXP 140 0
yr2[2000]=2000-2=1998
est_bugs[1998]=100
135
most typical SQL applies
136
SQL> select ...
7 model
8 dimension by (year as yr)
9 measures (ver,bugs, 0 est_bugs)
10 rules
11 (
12 est_bugs[yr is null]=100,
13 est_bugs[yr is not null]=110,
14 est_bugs[yr > 0]=120,
15 est_bugs[yr between 2000 and 2010]=130,
16 est_bugs[null]=140
17 );
YR VER BUGS EST_BUGS
---------- ------------ ---------- ----------
1995 Windows95 100 120
1998 Windows98 130 120
2000 WindowsME 170 130
2002 WindowsXP 140 130
(null) 140
137
idiosyncracies # 3
138
SQL> select year
2 ,ver
3 ,bugs
4 ,est_bugs
5 from versions
6 model
7 dimension by (platform,year)
8 measures (ver,bugs, 0 est_bugs)
9 rules
10 (
11 est_bugs[2009]=100
12 );
est_bugs[2009]=100
*
ERROR at line 11:
ORA-00947: not enough values
139
SQL> select year
2 ,ver
3 ,bugs
4 ,est_bugs
5 from versions
6 where platform = 'Win'
7 model
8 dimension by (year)
9 measures (ver,bugs, 0 est_bugs)
10 rules
11 (
12 est_bugs['Win',2009]=100
13 );
est_bugs['Win',2009]=100
*
ERROR at line 12:
ORA-00947: not enough values
140
rule aggregates
141
SQL> select year
2 ,ver
3 ,bugs
4 ,cumtot
5 from versions
6 where platform = 'Win'
7 model
8 dimension by (year)
9 measures (ver,bugs, 0 cumtot)
10 rules
11 ( cumtot[ANY]=SUM(bugs)[year <= CV(year)]
12 );
YEAR VER BUGS CUMTOT
---------- ------------ ---------- ----------
1995 Windows95 100 100
1998 Windows98 130 230
2000 WindowsME 170 400
2002 WindowsXP 140 540
142
SQL> select year
2 ,ver
3 ,bugs
4 ,wt
5 from versions
6 where platform = 'Win'
7 model
8 dimension by (year)
9 measures (ver,bugs, 0 wt)
10 rules
11 ( wt[ANY]=bugs[CV()]*
12 row_number() over ( order by year )
13 );
YEAR VER BUGS WT
---------- ------------ ---------- ----------
1995 Windows95 100 100
1998 Windows98 130 260
2000 WindowsME 170 510
2002 WindowsXP 140 560
143
rule conflict
144
SQL> select year
2 ,ver
3 ,bugs
4 from versions
5 where platform = 'Win'
6 model
7 dimension by (year)
8 measures (ver,bugs)
9 rules automatic order
10 ( bugs[2000]=150,
11 bugs[ANY]=bugs[CV()]*1.1
12 )
13 /
bugs[ANY]=bugs[CV()]*1.1
*
ERROR at line 11:
ORA-32630: multiple assignment in automatic
order MODEL
145
SQL> select year
2 ,ver
3 ,bugs
4 from versions
5 where platform = 'Win'
6 model
7 dimension by (year)
8 measures (ver,bugs)
9 rules sequential order
10 ( bugs[2000]=150,
11 bugs[ANY]=bugs[CV()]*1.1
12 )
13 /
YEAR VER BUGS
---------- --------------- ----------
1995 Windows95 110
1998 Windows98 143
2000 WindowsME 165
2002 WindowsXP 154
146
SQL> select year
2 ,ver
3 ,bugs
4 from versions
5 where platform = 'Win'
6 model
7 dimension by (year)
8 measures (ver,bugs)
9 rules sequential order
10 ( bugs[ANY]=bugs[CV()]*1.1,
11 bugs[2000]=150
12 )
13 /
YEAR VER BUGS
---------- --------------- ----------
1995 Windows95 110
1998 Windows98 143
2000 WindowsME 150
2002 WindowsXP 154
110
143
165
154
147
rule affected rows only
148
SQL> select year
2 ,ver
3 ,bugs
4 from versions
5 where platform = 'Win'
6 model return updated rows
7 dimension by (year)
8 measures (ver,bugs)
9 rules
10 ( ver[2009]='Windows7',
11 bugs[2009]=150
12 )
13 /
YEAR VER BUGS
---------- --------------- ----------
2009 Windows7 150
149
inter-row measures
150
151
SQL> select year
2 ,ver
3 ,bugs
4 ,est_bugs
5 from versions
6 where platform = 'Win'
7 model
8 dimension by (year)
9 measures (ver,bugs, 0 est_bugs)
10 rules
11 ( est_bugs[ANY]=bugs[CV()-1]*1.1
12 )
13 /
YEAR VER BUGS EST_BUGS
---------- --------------- ---------- ----------
1995 Windows95 100
1998 Windows98 130
2000 WindowsME 170
2002 WindowsXP 140
est_bugs[1995]=bugs[1994]
est_bugs[1998]=bugs[1997]
est_bugs[2000]=bugs[1999]
est_bugs[2002]=bugs[2001]
152
non-existent dimensions = null
153
SQL> select rank() over ( order by year) as year_rank
2 ,year
3 ,ver
4 ,bugs
5 from versions
6 where platform = 'Win'
7 /
YEAR_RANK YEAR VER BUGS
---------- ---------- --------------- ----------
1 1995 Windows95 100
2 1998 Windows98 130
3 2000 WindowsME 170
4 2002 WindowsXP 140
154
SQL> select year_rank,year
2 ,ver,bugs,est_bugs
3 from versions
4 where platform = 'Win'
5 model
6 dimension by (
7 rank() over ( order by year) as year_rank)
8 measures (ver,bugs,year,0 est_bugs)
9 rules
10 ( est_bugs[1]=bugs[1],
11 est_bugs[year_rank > 1]=bugs[CV()-1]*1.1
12 );
YEAR_RANK YEAR VER BUGS EST_BUGS
---------- ---------- --------------- ---------- ----------
1 1995 Windows95 100 100
2 1998 Windows98 130 110
3 2000 WindowsME 170 143
4 2002 WindowsXP 140 187
155
non-existent dimensions
in excel
156
157
158
SQL> select year_rank,year
2 ,ver,bugs,est_bugs
3 from versions
4 where platform = 'Win'
5 model
6 dimension by (
7 rank() over ( order by year) as year_rank)
8 measures (ver,bugs,year,0 est_bugs)
9 rules
10 ( est_bugs[1]=bugs[1],
11 est_bugs[year_rank > 1]=bugs[CV()-1]*1.1
12 );
YEAR_RANK YEAR VER BUGS EST_BUGS
---------- ---------- --------------- ---------- ----------
1 1995 Windows95 100 100
2 1998 Windows98 130 110
3 2000 WindowsME 170 143
4 2002 WindowsXP 140 187
159
SQL> select year_rank,year
2 ,ver,bugs,est_bugs
3 from versions
4 where platform = 'Win'
5 model
6 dimension by (
7 rank() over ( order by year) as year_rank)
8 measures (ver,bugs,year,0 est_bugs)
9 rules
10 ( est_bugs[ANY]=bugs[CV()-1]*1.1
11 );
YEAR_RANK YEAR VER BUGS EST_BUGS
---------- ---------- --------------- ---------- ----------
1 1995 Windows95 100
2 1998 Windows98 130 110
3 2000 WindowsME 170 143
4 2002 WindowsXP 140 187
160
but can be overridden
161
SQL> select year_rank,year
2 ,ver,bugs,est_bugs
3 from versions
4 where platform = 'Win'
5 model IGNORE NAV
6 dimension by (
7 rank() over ( order by year) as year_rank)
8 measures (ver,bugs,year,0 est_bugs)
9 rules
10 ( est_bugs[ANY]=bugs[CV()-1]*1.1
11 );
YEAR_RANK YEAR VER BUGS EST_BUGS
---------- ---------- --------------- ---------- ----------
1 1995 Windows95 100 0
2 1998 Windows98 130 110
3 2000 WindowsME 170 143
4 2002 WindowsXP 140 187
162
SQL> select *
2 from dual
3 where 1=0
4 model ignore nav
5 dimension by (0 tag)
6 measures (to_date(null) d,
7 to_number(null) n,
8 cast(null as varchar2(10)) v)
9 rules
10 ( d[0] = d[1],
11 n[0] = n[1],
12 v[0] = v[1]
13 );
TAG D N V
---------- ------------------- ---------- ------
0 01/01/2000 00:00:00 0
dimension 1 does not exist
beware documentation !
163
useful for cascading measures
164
SQL> select year_rank,year
2 ,ver,bugs,cum_bugs
3 from versions
4 where platform = 'Win'
5 model
6 dimension by (
7 rank() over ( order by year) as year_rank)
8 measures (ver,bugs,year,to_number(null) cum_bugs)
9 rules
10 ( cum_bugs[ANY]=cum_bugs[CV()-1]+bugs[CV()-1]
11 );
YEAR_RANK YEAR VER BUGS CUM_BUGS
---------- ---------- --------------- ---------- ----------
1 1995 Windows95 100
2 1998 Windows98 130
3 2000 WindowsME 170
4 2002 WindowsXP 140
165
SQL> select year_rank,year
2 ,ver,bugs,cum_bugs
3 from versions
4 where platform = 'Win'
5 model IGNORE NAV
6 dimension by (
7 rank() over ( order by year) as year_rank)
8 measures (ver,bugs,year,to_number(null) cum_bugs)
9 rules
10 ( cum_bugs[ANY]=cum_bugs[CV()-1]+bugs[CV()-1]
11 );
YEAR_RANK YEAR VER BUGS EST_BUGS
---------- ---------- --------------- ---------- ----------
1 1995 Windows95 100 0
2 1998 Windows98 130 100
3 2000 WindowsME 170 230
4 2002 WindowsXP 140 400
166
rule ordering
167
SQL> select ...
6 from versions
7 where platform = 'Win'
8 model
9 dimension by (rank() over ( order by year) as year_rank)
10 measures (ver,bugs,year,bugs est_bugs)
11 rules
12 (
13 est_bugs[ANY]=est_bugs[CV()-1]*1.1
14 );
YEAR_RANK YEAR VER BUGS EST_BUGS
---------- ---------- ------------ ---------- ----------
1 1995 Windows95 100
2 1998 Windows98 130
3 2000 WindowsME 170
4 2002 WindowsXP 140
168
SQL> select ...
6 from versions
7 where platform = 'Win'
8 model
9 dimension by (rank() over ( order by year) as year_rank)
10 measures (ver,bugs,year,bugs est_bugs)
11 rules
12 (
13 est_bugs[ANY] order by year_rank desc =
14 est_bugs[CV()-1]*1.1
15 );
YEAR_RANK YEAR VER BUGS EST_BUGS
---------- ---------- ------------ ---------- ----------
1 1995 Windows95 100
2 1998 Windows98 130 110
3 2000 WindowsME 170 143
4 2002 WindowsXP 140 187
169
lots of null "variations"
column is null
dimension does not exist
ignore nav / keep nav
170
SQL> select year, ver, bugs, patches
2 from versions
3 where platform = 'Win';
YEAR VER BUGS PATCHES
---------- --------------- ---------- ----------
1994 Windows3.1.1 140
1995 Windows95 100
1998 Windows98 130
2000 WindowsME 170
2002 WindowsXP 140 3
2003 Windows2003 140 1
FCAST
----------
(null)
(null)
(null)
(null)
(null)
110
"forecast = bugs(year-1) – 10*patches(year-1)"
171
SQL> select year, ver, patches, fcast, pv, pnv
2 from versions
3 where platform = 'Win'
4 model
5 dimension by ( year )
6 measures (ver, bugs, 0 fcast, patches, 'X' pv, 'X' pnv)
7 rules
8 (
9 fcast[ANY]=bugs[CV()]-10*patches[CV()-1],
10 pv[ANY]=PRESENTV( patches[CV()-1], 'Y','N'),
11 pnv[ANY]=PRESENTNNV( patches[CV()-1], 'Y','N')
12 );
YEAR VER PATCHES FCAST PV PNV
---------- --------------- ---------- ---------- ---- ----
1994 Windows3.1.1 N N
1995 Windows95 Y N
1998 Windows98 N N
2000 WindowsME N N
2002 WindowsXP 3 N N
2003 Windows2003 1 110 Y Y
172
"duh...I know about NVL"
resultset time
rule execution time
173
iteration
174
"if the number of bugs drops by
4% each year, what is the 5 year
forecast for each product"
Windows XP 140
Windows XP 134
Windows XP 129
Windows XP 123
Windows XP 118
Windows XP 113
175
SQL> select year, ver, bugs, bugs5yr
2 from versions
3 where platform = 'Win'
4 model
5 dimension by ( year )
6 measures (ver, bugs, bugs bugs5yr)
7 rules ITERATE(5)
8 (
9 bugs5yr[ANY]=bugs5yr[CV()] * 0.96
10 );
YEAR VER BUGS BUGS5YR
---------- --------------- ---------- -------
1995 Windows95 100 81.54
1998 Windows98 130 106.00
2000 WindowsME 170 138.61
2002 WindowsXP 140 114.15
176
5 iterations per partition
177
iteration_number
178
SQL> select num
2 from dual
3 model
4 dimension by ( 0 x)
5 measures ( 0 num)
6 rules iterate (20)
7 (
8 num[ITERATION_NUMBER]=ITERATION_NUMBER
9 );
NUM
----------
0
1
2
3
4
...
17
18
19
20 rows selected.
starts from zero
179
iterate UNTIL
180
loan payments
181
SQL> select *
2 from loans;
DESCR YEAR BAL RATE PMT
---------- ---------- ---------- ---------- ----------
Car 2000 25000 1.13 350
House 2010 300000 1.04 2200
182
SQL> select descr, bal final_bal, yrs
2 from loans
3 model
4 partition by ( year)
5 dimension by (0 idx)
6 measures (descr, bal, rate, pmt, 0 yrs)
7 rules iterate (50) until bal[0]*rate[0]-12*pmt[0]<0
8 (
9 bal[0]=bal[0]*rate[0]-12*pmt[0]
10 ,yrs[0]=iteration_number
11 );
DESCR FINAL_BAL YRS
---------- ----------- ----------
House 11660.34 14
Car 632.33 11
183
PREVIOUS
184
"how many years will it take for my
house to appreciate in value more
than my annual mortgage payments"
185
SQL> select year, bal, apprec, yrs
2 from loans
3 where descr = 'House'
4 model
5 partition by ( year )
6 dimension by ( 0 idx)
7 measures ( year y, bal, 12*pmt mort, apprec, 0 yrs)
8 rules iterate (20)
9 until bal[0]- previous( bal[0] ) > mort[0]
10 (
11 bal[0]=bal[0]*(1+apprec[0]/100),
12 yrs[0]=iteration_number+1
13 );
YEAR BAL APPREC YRS
---------- ---------- --------- ----------
2010 437742.689 6.5 6
186
reference models
187
SQL> select * from VERSIONS;
PLATFORM YEAR VER BUGS
---------- ---------- --------------- ----------
Win 1995 Windows95 100
Win 1998 Windows98 130
Win 2000 WindowsME 170
Win 2002 WindowsXP 140
Linux 1996 RedHat 50
Linux 2006 Oracle 80
Linux 2001 SUSE 65
Linux 2003 CentOS 90
SQL> select * from PLATFORM_TYPE;
PLATFORM OWNERSHIP
-------------------- --------------------
Win Private
Linux Open Source
188
SQL> select year, ver, bugs, est_bugs, own_ship
2 from versions
3 model
4 reference pt on
5 ( select platform p, ownership own
6 from platform_type )
7 dimension by (p)
8 measures (own)
9 dimension by (year)
10 measures (ver,bugs, 0 est_bugs,
11 platform, cast(null as varchar2(20)) own_ship)
12 rules
13 ( est_bugs[1995]=bugs[1995],
14 est_bugs[year > 1995]=bugs[cv()]*1.1,
15 own_ship[any]=pt.own[platform[cv()]]
16 );
YEAR VER BUGS EST_BUGS OWN_SHIP
---------- --------------- ---------- ---------- -----------
1995 Windows95 100 100 Private
1998 Windows98 130 143 Private
2000 WindowsME 170 187 Private
2002 WindowsXP 140 154 Private
1996 RedHat 50 55 Open Source
2006 Oracle 80 88 Open Source
2001 SUSE 65 71.5 Open Source
2003 CentOS 90 99 Open Source189
why not just a join ?
190
“imagination is more
important than knowledge”
- Albert Einstein
191
bit strings
192
SQL> create table DEC as
2 select rownum r
3 from dual connect by level < 1000;
Table created.
SQL> select * from DEC;
R
----------
1
2
3
4
5
6
7
8
9
10
193
SQL> select r, ltrim(str,'0')
2 from DEC
3 model
4 dimension by (r)
5 measures (
6 cast('' as varchar2(64)) str,
7 r as runtot,
8 power(2,32) as chk)
9 rules iterate(33)
10 ( str[ANY] =
11 str[CV()] ||
12 case
13 when bitand(runtot[CV()],chk[CV()]) > 0
14 then '1' else '0'
15 end,
16 runtot[ANY] =
17 runtot[CV()] -
18 bitand(runtot[CV()],chk[CV()]),
19 chk[ANY] = chk[CV()] / 2
20 );
194
R BITSTR
-------- -----------------
1 1
2 10
3 11
4 100
5 101
6 110
7 111
8 1000
9 1001
10 1010
11 1011
12 1100
13 1101
14 1110
15 1111
16 10000
17 10001
18 10010
195
or ...
196
select r, ltrim(str,'0')
from DEC
model
partition by (r)
dimension by (1 blah)
measures (
cast('' as varchar2(64)) str,
r as runtot,
power(2,32) as chk)
rules iterate(33)
( str[1] =
str[1] ||
case
when bitand(runtot[1],chk[1]) > 0
then '1' else '0'
end,
runtot[1] =
runtot[1] -
bitand(runtot[1],chk[1]),
chk[1] = chk[1] / 2
);
197
avoid self join
198
SQL> select e1.ename, e2.ename manager, e1.sal, e1.comm
2 from emp e1, emp e2
3 where e1.mgr= e2.empno;
ENAME MANAGER SAL COMM
---------- ---------- ---------- ----------
JONES KING 2975
CLARK KING 2450
BLAKE KING 2850
WARD BLAKE 1250 500
JAMES BLAKE 950
TURNER BLAKE 1500 0
ALLEN BLAKE 1600 300
MARTIN BLAKE 1250 1400
199
SQL> select ename, manager, sal, comm
2 from emp
3 model
4 dimension by (empno)
5 measures (ename, mgr, sal, comm,
6 cast (null as varchar2(10)) as manager)
7 rules (
8 manager[any] = ename[mgr[cv()]]
9 );
ENAME MANAGER SAL COMM
---------- ---------- ---------- ----------
KING ALLEN 5000
BLAKE KING 2850
CLARK KING 2450
JONES KING 2975
MARTIN BLAKE 1250 1400
ALLEN BLAKE 1600 300
...
200
string concatenation
pre 11.2
201
SQL> select deptno, ltrim(str,',') str
2 from emp
3 model return updated rows
4 partition by (deptno)
5 dimension by (
6 rank() over ( partition by deptno order by empno) x )
7 measures ( ename, cast('' as varchar2(4000)) str)
8 rules iterate (20)
9 until presentv(ename[iteration_number+1],1,2)=2
10 (
11 str[1] = str[1] || ','|| ename[iteration_number+1]
12 );
DEPTNO STR
---------- -------------------------------------------------
20 SMITH,JONES,SCOTT,ADAMS,FORD,
10 CLARK,KING,MILLER,
30 ALLEN,WARD,MARTIN,BLAKE,TURNER,JAMES,
202
obvious targets
203
SQL> select
2 col1,
3 col2,
4 my_function(...)
5 from EMP;
204
wrapup
205
why model ?
206
(largish) learning curve
207
SELECT c, p, m, pp, ip FROM MORTGAGE
MODEL
REFERENCE R ON
(SELECT customer, fact, amt FROM mortgage_facts
MODEL DIMENSION BY (customer, fact) MEASURES (amount amt)
RULES
(amt[any, 'PaymentAmt']= (amt[CV(),'Loan']*
Power(1+ (amt[CV(),'Annual_Interest']/100/12),
amt[CV(),'Payments']) *
(amt[CV(),'Annual_Interest']/100/12)) /
(Power(1+(amt[CV(),'Annual_Interest']/100/12),
amt[CV(),'Payments']) - 1)))
DIMENSION BY (customer cust, fact) measures (amt)
MAIN amortization
PARTITION BY (customer c)
DIMENSION BY (0 p)
MEASURES (principalp pp, interestp ip, mort_balance m, customer mc)
RULES
ITERATE(1000) UNTIL (ITERATION_NUMBER+1 =r.amt[mc[0],'Payments'])
(ip[ITERATION_NUMBER+1] = m[CV()-1] *
r.amt[mc[0], 'Annual_Interest']/1200,
pp[ITERATION_NUMBER+1] = r.amt[mc[0], 'PaymentAmt'] - ip[CV()],
m[ITERATION_NUMBER+1] = m[CV()-1] - pp[CV()] )
208
209
McDonald's Conjecture
210
you cannot kill Excel
211
let them !
212
all the work
formulas
layout rules
lookups
213
model equivalent
214
sharable
scalability
secure
flexible
215
accessible
216
ora-3113
217
Connor McDonald, www.oracledba.co.uk

More Related Content

Similar to The SQL Model Clause

Sq lite functions
Sq lite functionsSq lite functions
Sq lite functionspunu_82
 
Win cc comfort-(tia-portal)-v13.0-compatibility-list-zh-2017-05-5
Win cc comfort-(tia-portal)-v13.0-compatibility-list-zh-2017-05-5Win cc comfort-(tia-portal)-v13.0-compatibility-list-zh-2017-05-5
Win cc comfort-(tia-portal)-v13.0-compatibility-list-zh-2017-05-5
Yan Zhang
 
Please follow the data 1) For Line 23 In the IF - Condition yo.pdf
Please follow the data 1) For Line 23 In the IF - Condition yo.pdfPlease follow the data 1) For Line 23 In the IF - Condition yo.pdf
Please follow the data 1) For Line 23 In the IF - Condition yo.pdf
info382133
 
OSMC 2008 | Monitoring MySQL by Geert Vanderkelen
OSMC 2008 | Monitoring MySQL by Geert VanderkelenOSMC 2008 | Monitoring MySQL by Geert Vanderkelen
OSMC 2008 | Monitoring MySQL by Geert Vanderkelen
NETWAYS
 
Riyaj: why optimizer_hates_my_sql_2010
Riyaj: why optimizer_hates_my_sql_2010Riyaj: why optimizer_hates_my_sql_2010
Riyaj: why optimizer_hates_my_sql_2010
Riyaj Shamsudeen
 
My old security advisories on HMI/SCADA and industrial software released betw...
My old security advisories on HMI/SCADA and industrial software released betw...My old security advisories on HMI/SCADA and industrial software released betw...
My old security advisories on HMI/SCADA and industrial software released betw...
Luigi Auriemma
 
Practice 1
Practice 1Practice 1
Practice 1nonamela
 
Optimizer in oracle 11g by wwf from ebay COC
Optimizer in oracle 11g by wwf from ebay COCOptimizer in oracle 11g by wwf from ebay COC
Optimizer in oracle 11g by wwf from ebay COC
Louis liu
 
R Language
R LanguageR Language
R Language
ShwetDadhaniya1
 
SQL Tuning 101 - Sep 2013
SQL Tuning 101 - Sep 2013SQL Tuning 101 - Sep 2013
SQL Tuning 101 - Sep 2013
Connor McDonald
 
Hailey_Database_Performance_Made_Easy_through_Graphics.pdf
Hailey_Database_Performance_Made_Easy_through_Graphics.pdfHailey_Database_Performance_Made_Easy_through_Graphics.pdf
Hailey_Database_Performance_Made_Easy_through_Graphics.pdf
cookie1969
 
SQL and PLSQL features for APEX Developers
SQL and PLSQL features for APEX DevelopersSQL and PLSQL features for APEX Developers
SQL and PLSQL features for APEX Developers
Connor McDonald
 
Agent sss 33_en
Agent sss 33_enAgent sss 33_en
Agent sss 33_en
Thái Đức Phương
 
2012 09 MariaDB Boston Meetup - MariaDB 是 Mysql 的替代者吗
2012 09 MariaDB Boston Meetup - MariaDB 是 Mysql 的替代者吗2012 09 MariaDB Boston Meetup - MariaDB 是 Mysql 的替代者吗
2012 09 MariaDB Boston Meetup - MariaDB 是 Mysql 的替代者吗
YUCHENG HU
 
Java exercise1
Java exercise1Java exercise1
Java exercise1
Jainul Musani
 
SQL Macros - Game Changing Feature for SQL Developers?
SQL Macros - Game Changing Feature for SQL Developers?SQL Macros - Game Changing Feature for SQL Developers?
SQL Macros - Game Changing Feature for SQL Developers?
Andrej Pashchenko
 
Discovering and querying temporal data
Discovering and querying temporal dataDiscovering and querying temporal data
Discovering and querying temporal data
MariaDB plc
 
OOW19 - Ten Amazing SQL features
OOW19 - Ten Amazing SQL featuresOOW19 - Ten Amazing SQL features
OOW19 - Ten Amazing SQL features
Connor McDonald
 
MySQLinsanity
MySQLinsanityMySQLinsanity
MySQLinsanity
Stanley Huang
 
Tic tac toe c++ programing
Tic tac toe c++ programingTic tac toe c++ programing
Tic tac toe c++ programing
Krishna Agarwal
 

Similar to The SQL Model Clause (20)

Sq lite functions
Sq lite functionsSq lite functions
Sq lite functions
 
Win cc comfort-(tia-portal)-v13.0-compatibility-list-zh-2017-05-5
Win cc comfort-(tia-portal)-v13.0-compatibility-list-zh-2017-05-5Win cc comfort-(tia-portal)-v13.0-compatibility-list-zh-2017-05-5
Win cc comfort-(tia-portal)-v13.0-compatibility-list-zh-2017-05-5
 
Please follow the data 1) For Line 23 In the IF - Condition yo.pdf
Please follow the data 1) For Line 23 In the IF - Condition yo.pdfPlease follow the data 1) For Line 23 In the IF - Condition yo.pdf
Please follow the data 1) For Line 23 In the IF - Condition yo.pdf
 
OSMC 2008 | Monitoring MySQL by Geert Vanderkelen
OSMC 2008 | Monitoring MySQL by Geert VanderkelenOSMC 2008 | Monitoring MySQL by Geert Vanderkelen
OSMC 2008 | Monitoring MySQL by Geert Vanderkelen
 
Riyaj: why optimizer_hates_my_sql_2010
Riyaj: why optimizer_hates_my_sql_2010Riyaj: why optimizer_hates_my_sql_2010
Riyaj: why optimizer_hates_my_sql_2010
 
My old security advisories on HMI/SCADA and industrial software released betw...
My old security advisories on HMI/SCADA and industrial software released betw...My old security advisories on HMI/SCADA and industrial software released betw...
My old security advisories on HMI/SCADA and industrial software released betw...
 
Practice 1
Practice 1Practice 1
Practice 1
 
Optimizer in oracle 11g by wwf from ebay COC
Optimizer in oracle 11g by wwf from ebay COCOptimizer in oracle 11g by wwf from ebay COC
Optimizer in oracle 11g by wwf from ebay COC
 
R Language
R LanguageR Language
R Language
 
SQL Tuning 101 - Sep 2013
SQL Tuning 101 - Sep 2013SQL Tuning 101 - Sep 2013
SQL Tuning 101 - Sep 2013
 
Hailey_Database_Performance_Made_Easy_through_Graphics.pdf
Hailey_Database_Performance_Made_Easy_through_Graphics.pdfHailey_Database_Performance_Made_Easy_through_Graphics.pdf
Hailey_Database_Performance_Made_Easy_through_Graphics.pdf
 
SQL and PLSQL features for APEX Developers
SQL and PLSQL features for APEX DevelopersSQL and PLSQL features for APEX Developers
SQL and PLSQL features for APEX Developers
 
Agent sss 33_en
Agent sss 33_enAgent sss 33_en
Agent sss 33_en
 
2012 09 MariaDB Boston Meetup - MariaDB 是 Mysql 的替代者吗
2012 09 MariaDB Boston Meetup - MariaDB 是 Mysql 的替代者吗2012 09 MariaDB Boston Meetup - MariaDB 是 Mysql 的替代者吗
2012 09 MariaDB Boston Meetup - MariaDB 是 Mysql 的替代者吗
 
Java exercise1
Java exercise1Java exercise1
Java exercise1
 
SQL Macros - Game Changing Feature for SQL Developers?
SQL Macros - Game Changing Feature for SQL Developers?SQL Macros - Game Changing Feature for SQL Developers?
SQL Macros - Game Changing Feature for SQL Developers?
 
Discovering and querying temporal data
Discovering and querying temporal dataDiscovering and querying temporal data
Discovering and querying temporal data
 
OOW19 - Ten Amazing SQL features
OOW19 - Ten Amazing SQL featuresOOW19 - Ten Amazing SQL features
OOW19 - Ten Amazing SQL features
 
MySQLinsanity
MySQLinsanityMySQLinsanity
MySQLinsanity
 
Tic tac toe c++ programing
Tic tac toe c++ programingTic tac toe c++ programing
Tic tac toe c++ programing
 

More from Connor McDonald

Flashback ITOUG
Flashback ITOUGFlashback ITOUG
Flashback ITOUG
Connor McDonald
 
Sangam 19 - PLSQL still the coolest
Sangam 19 - PLSQL still the coolestSangam 19 - PLSQL still the coolest
Sangam 19 - PLSQL still the coolest
Connor McDonald
 
Sangam 19 - Analytic SQL
Sangam 19 - Analytic SQLSangam 19 - Analytic SQL
Sangam 19 - Analytic SQL
Connor McDonald
 
UKOUG - 25 years of hints and tips
UKOUG - 25 years of hints and tipsUKOUG - 25 years of hints and tips
UKOUG - 25 years of hints and tips
Connor McDonald
 
Sangam 19 - Successful Applications on Autonomous
Sangam 19 - Successful Applications on AutonomousSangam 19 - Successful Applications on Autonomous
Sangam 19 - Successful Applications on Autonomous
Connor McDonald
 
APEX tour 2019 - successful development with autonomous
APEX tour 2019 - successful development with autonomousAPEX tour 2019 - successful development with autonomous
APEX tour 2019 - successful development with autonomous
Connor McDonald
 
APAC Groundbreakers 2019 - Perth/Melbourne
APAC Groundbreakers 2019 - Perth/Melbourne APAC Groundbreakers 2019 - Perth/Melbourne
APAC Groundbreakers 2019 - Perth/Melbourne
Connor McDonald
 
OOW19 - Flashback, not just for DBAs
OOW19 - Flashback, not just for DBAsOOW19 - Flashback, not just for DBAs
OOW19 - Flashback, not just for DBAs
Connor McDonald
 
OOW19 - Read consistency
OOW19 - Read consistencyOOW19 - Read consistency
OOW19 - Read consistency
Connor McDonald
 
OOW19 - Slower and less secure applications
OOW19 - Slower and less secure applicationsOOW19 - Slower and less secure applications
OOW19 - Slower and less secure applications
Connor McDonald
 
OOW19 - Killing database sessions
OOW19 - Killing database sessionsOOW19 - Killing database sessions
OOW19 - Killing database sessions
Connor McDonald
 
Latin America Tour 2019 - 18c and 19c featues
Latin America Tour 2019   - 18c and 19c featuesLatin America Tour 2019   - 18c and 19c featues
Latin America Tour 2019 - 18c and 19c featues
Connor McDonald
 
Latin America tour 2019 - Flashback
Latin America tour 2019 -  FlashbackLatin America tour 2019 -  Flashback
Latin America tour 2019 - Flashback
Connor McDonald
 
Latin America Tour 2019 - 10 great sql features
Latin America Tour 2019  - 10 great sql featuresLatin America Tour 2019  - 10 great sql features
Latin America Tour 2019 - 10 great sql features
Connor McDonald
 
Latin America Tour 2019 - pattern matching
Latin America Tour 2019 - pattern matchingLatin America Tour 2019 - pattern matching
Latin America Tour 2019 - pattern matching
Connor McDonald
 
Latin America Tour 2019 - slow data and sql processing
Latin America Tour 2019  - slow data and sql processingLatin America Tour 2019  - slow data and sql processing
Latin America Tour 2019 - slow data and sql processing
Connor McDonald
 
ANSI vs Oracle language
ANSI vs Oracle languageANSI vs Oracle language
ANSI vs Oracle language
Connor McDonald
 
OG Yatra - upgrading to the new 12c+ optimizer
OG Yatra - upgrading to the new 12c+ optimizerOG Yatra - upgrading to the new 12c+ optimizer
OG Yatra - upgrading to the new 12c+ optimizer
Connor McDonald
 
OG Yatra - 25 years of hints and tips
OG Yatra - 25 years of hints and tipsOG Yatra - 25 years of hints and tips
OG Yatra - 25 years of hints and tips
Connor McDonald
 
OG Yatra - Flashback, not just for developers
OG Yatra - Flashback, not just for developersOG Yatra - Flashback, not just for developers
OG Yatra - Flashback, not just for developers
Connor McDonald
 

More from Connor McDonald (20)

Flashback ITOUG
Flashback ITOUGFlashback ITOUG
Flashback ITOUG
 
Sangam 19 - PLSQL still the coolest
Sangam 19 - PLSQL still the coolestSangam 19 - PLSQL still the coolest
Sangam 19 - PLSQL still the coolest
 
Sangam 19 - Analytic SQL
Sangam 19 - Analytic SQLSangam 19 - Analytic SQL
Sangam 19 - Analytic SQL
 
UKOUG - 25 years of hints and tips
UKOUG - 25 years of hints and tipsUKOUG - 25 years of hints and tips
UKOUG - 25 years of hints and tips
 
Sangam 19 - Successful Applications on Autonomous
Sangam 19 - Successful Applications on AutonomousSangam 19 - Successful Applications on Autonomous
Sangam 19 - Successful Applications on Autonomous
 
APEX tour 2019 - successful development with autonomous
APEX tour 2019 - successful development with autonomousAPEX tour 2019 - successful development with autonomous
APEX tour 2019 - successful development with autonomous
 
APAC Groundbreakers 2019 - Perth/Melbourne
APAC Groundbreakers 2019 - Perth/Melbourne APAC Groundbreakers 2019 - Perth/Melbourne
APAC Groundbreakers 2019 - Perth/Melbourne
 
OOW19 - Flashback, not just for DBAs
OOW19 - Flashback, not just for DBAsOOW19 - Flashback, not just for DBAs
OOW19 - Flashback, not just for DBAs
 
OOW19 - Read consistency
OOW19 - Read consistencyOOW19 - Read consistency
OOW19 - Read consistency
 
OOW19 - Slower and less secure applications
OOW19 - Slower and less secure applicationsOOW19 - Slower and less secure applications
OOW19 - Slower and less secure applications
 
OOW19 - Killing database sessions
OOW19 - Killing database sessionsOOW19 - Killing database sessions
OOW19 - Killing database sessions
 
Latin America Tour 2019 - 18c and 19c featues
Latin America Tour 2019   - 18c and 19c featuesLatin America Tour 2019   - 18c and 19c featues
Latin America Tour 2019 - 18c and 19c featues
 
Latin America tour 2019 - Flashback
Latin America tour 2019 -  FlashbackLatin America tour 2019 -  Flashback
Latin America tour 2019 - Flashback
 
Latin America Tour 2019 - 10 great sql features
Latin America Tour 2019  - 10 great sql featuresLatin America Tour 2019  - 10 great sql features
Latin America Tour 2019 - 10 great sql features
 
Latin America Tour 2019 - pattern matching
Latin America Tour 2019 - pattern matchingLatin America Tour 2019 - pattern matching
Latin America Tour 2019 - pattern matching
 
Latin America Tour 2019 - slow data and sql processing
Latin America Tour 2019  - slow data and sql processingLatin America Tour 2019  - slow data and sql processing
Latin America Tour 2019 - slow data and sql processing
 
ANSI vs Oracle language
ANSI vs Oracle languageANSI vs Oracle language
ANSI vs Oracle language
 
OG Yatra - upgrading to the new 12c+ optimizer
OG Yatra - upgrading to the new 12c+ optimizerOG Yatra - upgrading to the new 12c+ optimizer
OG Yatra - upgrading to the new 12c+ optimizer
 
OG Yatra - 25 years of hints and tips
OG Yatra - 25 years of hints and tipsOG Yatra - 25 years of hints and tips
OG Yatra - 25 years of hints and tips
 
OG Yatra - Flashback, not just for developers
OG Yatra - Flashback, not just for developersOG Yatra - Flashback, not just for developers
OG Yatra - Flashback, not just for developers
 

Recently uploaded

Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
UiPathCommunity
 
Introduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - CybersecurityIntroduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - Cybersecurity
mikeeftimakis1
 
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
SOFTTECHHUB
 
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex ProofszkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
Alex Pruden
 
Assure Contact Center Experiences for Your Customers With ThousandEyes
Assure Contact Center Experiences for Your Customers With ThousandEyesAssure Contact Center Experiences for Your Customers With ThousandEyes
Assure Contact Center Experiences for Your Customers With ThousandEyes
ThousandEyes
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
DanBrown980551
 
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdfSAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
Peter Spielvogel
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
Jemma Hussein Allen
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
Guy Korland
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
KatiaHIMEUR1
 
Removing Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software FuzzingRemoving Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software Fuzzing
Aftab Hussain
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
DianaGray10
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
Alpen-Adria-Universität
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
ControlCase
 
RESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for studentsRESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for students
KAMESHS29
 
A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...
sonjaschweigert1
 
Elevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object CalisthenicsElevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object Calisthenics
Dorra BARTAGUIZ
 
Quantum Computing: Current Landscape and the Future Role of APIs
Quantum Computing: Current Landscape and the Future Role of APIsQuantum Computing: Current Landscape and the Future Role of APIs
Quantum Computing: Current Landscape and the Future Role of APIs
Vlad Stirbu
 

Recently uploaded (20)

Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
 
Introduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - CybersecurityIntroduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - Cybersecurity
 
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
 
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex ProofszkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
 
Assure Contact Center Experiences for Your Customers With ThousandEyes
Assure Contact Center Experiences for Your Customers With ThousandEyesAssure Contact Center Experiences for Your Customers With ThousandEyes
Assure Contact Center Experiences for Your Customers With ThousandEyes
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
 
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdfSAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
 
Removing Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software FuzzingRemoving Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software Fuzzing
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
 
RESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for studentsRESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for students
 
A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...
 
Elevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object CalisthenicsElevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object Calisthenics
 
Quantum Computing: Current Landscape and the Future Role of APIs
Quantum Computing: Current Landscape and the Future Role of APIsQuantum Computing: Current Landscape and the Future Role of APIs
Quantum Computing: Current Landscape and the Future Role of APIs
 

The SQL Model Clause

  • 1. 1
  • 3. 3
  • 4. 4
  • 8. 8
  • 9. 9
  • 10. 10
  • 11. 11
  • 12. 12
  • 13.
  • 14. McDonald's Conjecture on Large Corporations: 14
  • 15. "you cannot kill Excel" 15
  • 16. 16
  • 18. 18
  • 19. 19
  • 20. 20
  • 21. you cannot kill Excel 21
  • 23. 23
  • 24. 24
  • 28. 28
  • 30. 30
  • 31. formulas inter-row calculations familiar excel expressions ...all in SQL 31
  • 33. 33
  • 35. my first MODEL query 35
  • 36. SQL> select year 2 ,ver 3 ,bugs 4 from versions 5 where platform = 'Win'; YEAR VER BUGS ---------- --------------- ---------- 1995 Windows95 100 1998 Windows98 130 2000 WindowsME 170 2002 WindowsXP 140 36
  • 37. SQL> select year 2 ,ver 3 ,bugs 4 from versions 5 where platform = 'Win'; YEAR VER BUGS ---------- --------------- ---------- 1995 Windows95 100 1998 Windows98 130 2000 WindowsME 170 2002 WindowsXP 140 37
  • 39. SQL> select year 2 ,ver 3 ,bugs 4 from versions 5 where platform = 'Win' 6 model 7 dimension by (year) 8 measures (ver,bugs) 9 rules 10 () 11 / YEAR VER BUGS ---------- --------------- ---------- 1995 Windows95 100 1998 Windows98 130 2000 WindowsME 170 2002 WindowsXP 140 39
  • 40. paid by line of code ... 40
  • 41. SQL> select year 2 ,ver 3 ,bugs 4 from versions 5 where platform = 'Win' 6 model 7 dimension by (year) 8 measures (ver,bugs) 9 rules 10 () 11 / 41
  • 44. SQL> select year 2 ,ver 3 ,bugs 4 from versions 5 where platform = 'Win' 6 model 7 dimension by (year) 8 measures (ver,bugs) 9 rules 10 () 11 / 44
  • 47. SQL> select year 2 ,ver 3 ,bugs 4 from versions 5 where platform = 'Win' 6 model 7 dimension by (year) 8 measures (ver,bugs) 9 rules 10 () 11 / 47
  • 49. SQL> select year 2 ,ver 3 ,bugs 4 from versions 5 where platform = 'Win' 6 model 7 dimension by (year) 8 measures (ver,bugs) 9 rules 10 ( ver[2009]='Windows7', 11 bugs[2009]=150 ); 49
  • 50. SQL> select year 2 ,ver 3 ,bugs 4 from versions 5 where platform = 'Win' 6 model 7 dimension by (year) 8 measures (ver,bugs) 9 rules 10 ( ver[2009]='Windows7', 11 bugs[2009]=150 ); 50
  • 51. SQL> select year 2 ,ver 3 ,bugs 4 from versions 5 where platform = 'Win' 6 model 7 dimension by (year) 8 measures (ver,bugs) 9 rules 10 ( ver[2009]='Windows7', 11 bugs[2009]=150 ); 51
  • 52. SQL> select year 2 ,ver 3 ,bugs 4 from versions 5 where platform = 'Win' 6 model 7 dimension by (year) 8 measures (ver,bugs) 9 rules 10 ( ver[2009]='Windows7', 11 bugs[2009]=150 12 ) 13 / YEAR VER BUGS ---------- --------------- ---------- 1995 Windows95 100 1998 Windows98 130 2000 WindowsME 170 2002 WindowsXP 140 2009 Windows7 150 52
  • 54. you'll still need "Excel" Discoverer APEX Crystal Reports 54
  • 57. 57
  • 59. SQL> select year 2 ,ver 3 ,bugs 4 ,est_bugs 5 from versions 6 where platform = 'Win' 7 model 8 dimension by (year) 9 measures (ver,bugs, 0 est_bugs) 10 rules sequential order 11 ( est_bugs[1995]=100 ) 12 order by year; YEAR VER BUGS EST_BUGS ---------- --------------- ---------- ---------- 1995 Windows95 100 100 1998 Windows98 130 0 2000 WindowsME 170 0 2002 WindowsXP 140 0 59
  • 60. 60
  • 61. SQL> select year 2 ,ver 3 ,bugs 4 ,est_bugs 5 from versions 6 where platform = 'Win' 7 model 8 dimension by (year) 9 measures (ver,bugs, 0 est_bugs) 10 rules sequential order 11 ( 12 est_bugs[1995]=100 , 13 est_bugs[1998]=100 , 14 est_bugs[2000]=100 , 15 est_bugs[2002]=100 16 ... 61
  • 62. SQL> select year 2 ,ver 3 ,bugs 4 ,est_bugs 5 from versions 6 where platform = 'Win' 7 model 8 dimension by (year) 9 measures (ver,bugs, 0 est_bugs) 10 rules sequential order 11 ( 12 est_bugs[ANY]=100 13 ); YEAR VER BUGS EST_BUGS ---------- --------------- ---------- ---------- 1995 Windows95 100 100 1998 Windows98 130 100 2000 WindowsME 170 100 2002 WindowsXP 140 100 62
  • 63. 63
  • 64. SQL> select year 2 ,ver 3 ,bugs 4 ,est_bugs 5 from versions 6 where platform = 'Win' 7 model 8 dimension by (year) 9 measures (ver,bugs, 0 est_bugs) 10 rules sequential order 11 ( est_bugs[1995]=bugs[1995]*1.1 ) 12 order by year; YEAR VER BUGS EST_BUGS ---------- --------------- ---------- ---------- 1995 Windows95 100 110 1998 Windows98 130 0 2000 WindowsME 170 0 2002 WindowsXP 140 0 64
  • 65. 65
  • 67. SQL> select year 2 ,ver 3 ,bugs 4 ,est_bugs 5 from versions 6 where platform = 'Win' 7 model 8 dimension by (year) 9 measures (ver,bugs, 0 est_bugs) 10 rules 11 ( est_bugs[ANY]=bugs[CV()]*1.1 12 ) 13 / YEAR VER BUGS EST_BUGS ---------- --------------- ---------- ---------- 1995 Windows95 100 110 1998 Windows98 130 143 2000 WindowsME 170 187 2002 WindowsXP 140 154 67
  • 69. 69
  • 70. SQL> select year 2 ,ver 3 ,bugs 4 ,est_bugs 5 from versions 6 where platform = 'Win' 7 model 8 dimension by (department, year) 9 measures (ver,bugs, 0 est_bugs) 10 rules 11 ( est_bugs['HR', ANY]=bugs['HR', CV()]*1.1 12 ( est_bugs['Sales', ANY]=bugs['Sales', CV()]*1.2 13 ( est_bugs['Payroll', ANY]=bugs['Payroll', CV()]*1.5 14 ) 15 / not just numeric 70
  • 71. 71
  • 73. SQL> select year 2 ,ver 3 ,bugs 4 ,est_bugs 5 from versions 6 model 7 dimension by (year) 8 measures (ver,bugs, 0 est_bugs) 9 rules 10 ( 11 ); YR VER BUGS EST_BUGS ---------- --------------- ---------- ---------- 1995 Windows95 100 0 1998 Windows98 130 0 2000 WindowsME 170 0 2002 WindowsXP 140 0 1996 RedHat 50 0 2006 Oracle 80 0 2001 SUSE 65 0 2003 CentOS 90 0 73
  • 74. SQL> insert into versions 2 values ('Linux',2001,'Fedora',70); 1 row created. SQL> select yr 2 ,ver 3 ,bugs 4 ,est_bugs 5 from versions 6 model 7 dimension by (year as yr) 8 measures (ver,bugs, 0 est_bugs) 9 rules 10 ( 11 ); from versions * ERROR at line 5: ORA-32638: Non unique addressing in MODEL dimensions 74
  • 75. 75
  • 76. SQL> select yr 2 ,ver 3 ,bugs 4 ,est_bugs 5 from versions 6 model UNIQUE SINGLE REFERENCE 7 dimension by (year as yr) 8 measures (ver,bugs, 0 est_bugs) 9 rules ( ); YR VER BUGS EST_BUGS ---------- --------------- ---------- ---------- 1995 Windows95 100 0 1998 Windows98 130 0 2000 WindowsME 170 0 2002 WindowsXP 140 0 1996 RedHat 50 0 2006 Oracle 80 0 2001 SUSE 65 0 2003 CentOS 90 0 2001 Fedora 70 0 76
  • 77. unique single reference rules cannot cross dimensions 77
  • 78. dimensions can be null 78
  • 79. SQL> select yr,ver,bugs,est_bugs 2 from versions 3 where platform = 'Win' 4 model 5 dimension by (year as yr) 6 measures (ver,bugs, 0 est_bugs) 7 rules 8 ( 9 est_bugs[null]=140 10 ); YR VER BUGS EST_BUGS ---------- --------------- ---------- ---------- 1995 Windows95 100 0 1998 Windows98 130 0 2000 WindowsME 170 0 2002 WindowsXP 140 0 (null) 140 79
  • 81. SQL> select year as yr 2 ,ver 3 ,bugs 4 ,est_bugs 5 from versions 6 model 7 dimension by (yr) 8 measures (ver,bugs, 0 est_bugs) 9 rules 10 ( 11 ); dimension by (yr) * ERROR at line 7: ORA-00904: "YR": invalid identifier 81
  • 82. SQL> select yr 2 ,ver 3 ,bugs 4 ,est_bugs 5 from versions 6 model 7 dimension by (year as yr) 8 measures (ver,bugs, 0 est_bugs) 9 rules 10 ( 11 ); YR VER BUGS EST_BUGS ---------- --------------- ---------- ---------- 1995 Windows95 100 0 1998 Windows98 130 0 2000 WindowsME 170 0 2002 WindowsXP 140 0 1996 RedHat 50 0 2006 Oracle 80 0 2001 SUSE 65 0 2003 CentOS 90 0 82
  • 85. SQL> select ... 7 model 8 dimension by (year) 9 measures (ver, 10 bugs, 11 bugs*0.5 half_bugs, 12 avg(bugs) over ( 13 order by year rows 14 between 1 preceding 15 and 1 following ) est_bugs) 16 rules 17 ( 18 ); YEAR VER BUGS HALF_BUGS EST_BUGS ---------- ------------ ---------- ---------- ---------- 1995 Windows95 100 50 115 1998 Windows98 130 65 133.333333 2000 WindowsME 170 85 146.666667 2002 WindowsXP 140 70 155 85
  • 87. SQL> select platform, tot_bugs 2 from versions 3 group by platform 4 model 5 dimension by (platform) 6 measures (sum(bugs) as tot_bugs) 7 rules 8 ( 9 ); PLATFORM TOT_BUGS ---------- ---------- Linux 285 Win 540 87
  • 89. SQL> select platform, sum(bugs) as tot_bugs 2 from versions 3 group by platform 4 model 5 dimension by (platform) 6 measures (tot_bugs) 7 rules 8 ( 9 ); measures (tot_bugs) * ERROR at line 6: ORA-00904: "TOT_BUGS": invalid identifier 89
  • 91. SQL> select platform, year, ver, bugs 2 from versions 3 where platform = 'Win' 4 model 5 dimension by (year) 6 measures (ver,bugs) 7 rules 8 ( ver[2009]='Windows7', 9 bugs[2009]=150 10 ); select platform, year, ver, bugs * ERROR at line 1: ORA-32614: illegal MODEL SELECT expression 91
  • 92. SQL> select platform, year, ver, bugs 2 from versions 3 where platform = 'Win' 4 model 5 dimension by (year) 6 measures (ver,bugs,platform) 7 rules 8 ( ver[2009]='Windows7', 9 bugs[2009]=150 10 ); PLATFORM YEAR VER BUGS ---------- ---------- --------------- ---------- Win 1995 Windows95 100 Win 1998 Windows98 130 Win 2000 WindowsME 170 Win 2002 WindowsXP 140 2009 Windows7 150 92
  • 94. SQL> select year, ver, bugs 2 from versions 3 where platform = 'Win' 4 model 5 dimension by (year) 6 measures (ver,bugs,year) 7 rules 8 ( ver[2009]='Windows7', 9 bugs[2009]=150, 10 year[2009]=2010 11 ); select year, ver, bugs * ERROR at line 1: ORA-00957: duplicate column name 94
  • 95. SQL> select year, ver, bugs 2 from versions 3 where platform = 'Win' 4 model 5 dimension by (year) 6 measures (ver,bugs,year next_year) 7 rules 8 ( ver[2009]='Windows7', 9 bugs[2009]=150, 10 next_year[2009]=2010 11 ); YEAR VER BUGS ---------- --------------- ---------- 1995 Windows95 100 1998 Windows98 130 2000 WindowsME 170 2002 WindowsXP 140 2009 Windows7 150 95
  • 96. SQL> select year, ver, bugs, next_year 2 from versions 3 where platform = 'Win' 4 model 5 dimension by (year) 6 measures (ver,bugs,year next_year) 7 rules 8 ( ver[2009]='Windows7', 9 bugs[2009]=150, 10 next_year[2009]=2010 11 ); YEAR VER BUGS NEXT_YEAR ---------- --------------- ---------- ---------- 1995 Windows95 100 1995 1998 Windows98 130 1998 2000 WindowsME 170 2000 2002 WindowsXP 140 2002 2009 Windows7 150 2010 96
  • 98. SQL> select year, ver, bugs 2 from versions 3 where platform = 'Win' 4 model 5 dimension by (year) 6 measures (ver,bugs,null est_sales) 7 rules 8 ( 9 est_sales[ANY]=0 10 ); measures (ver,bugs,null est_sales) * ERROR at line 6: ORA-01723: zero-length columns are not allowed 98
  • 99. SQL> select year, ver, bugs 2 from versions 3 where platform = 'Win' 4 model 5 dimension by (year) 6 measures (ver,bugs,to_number(null) est_sales) 7 rules 8 ( 9 est_sales[ANY]=0 10 ); YEAR VER BUGS ---------- --------------- ---------- 1995 Windows95 100 1998 Windows98 130 2000 WindowsME 170 2002 WindowsXP 140 99
  • 100. SQL> select year, ver, bugs, sales_rep 2 from versions 3 where platform = 'Win' 4 model 5 dimension by (year) 6 measures (ver,bugs, 7 cast(null as varchar2(20)) sales_rep) 8 rules 9 ( 10 sales_rep[2000]='Mike' 11 ); YEAR VER BUGS SALES_REP ---------- --------------- ---------- -------------------- 1995 Windows95 100 1998 Windows98 130 2002 WindowsXP 140 2000 WindowsME 170 Mike 100
  • 101. SQL> select year, ver, bugs, sales_rep 2 from versions 3 where platform = 'Win' 4 model 5 dimension by (year) 6 measures (ver,bugs,'Unknown' sales_rep) 7 rules 8 ( 9 sales_rep[2000]='Mike Jones' 10 ); ERROR: ORA-25137: Data value out of range 101
  • 102. SQL> select year, ver, bugs, sales_rep 2 from versions 3 where platform = 'Win' 4 model 5 dimension by (year) 6 measures (ver,bugs, 7 cast('Unknown' as varchar2(20)) sales_rep) 8 rules 9 ( 10 sales_rep[2000]='Mike Jones' 11 ); YEAR VER BUGS SALES_REP ---------- --------------- ---------- -------------------- 1995 Windows95 100 Unknown 1998 Windows98 130 Unknown 2002 WindowsXP 140 Unknown 2000 WindowsME 170 Mike Jones 102
  • 104. 104
  • 105. SQL> select platform ... 6 from versions 7 model 8 partition by ( platform ) 9 dimension by (year) 10 measures (ver,bugs, 0 est_bugs) 11 rules 12 ( est_bugs[1995]=bugs[1995], 13 est_bugs[year > 1995]=bugs[CV()]*1.1 14 ); PLATFORM YEAR VER BUGS EST_BUGS ---------- ---------- --------------- ---------- ---------- Linux 1996 RedHat 50 55 Linux 2006 Oracle 80 88 Linux 2001 SUSE 65 71.5 Linux 2003 CentOS 90 99 Linux 1995 Win 1995 Windows95 100 100 Win 1998 Windows98 130 143 Win 2000 WindowsME 170 187 Win 2002 WindowsXP 140 154 105
  • 106. rules applied per partition 106
  • 109. SQL> select yr 2 ,ver 3 ,bugs 4 ,est_bugs 5 from versions 6 where platform = 'Win' 7 model 8 dimension by (year as yr) 9 measures (ver,bugs, 0 est_bugs) 10 rules 11 ( 12 est_bugs[1998]=100, 13 bugs[2000]= :bindvar, 14 est_bugs[2009]= dbms_random.value(80,100) 15 ); YR VER BUGS EST_BUGS ---------- ------------ ---------- ---------- 1995 Windows95 100 0 2002 WindowsXP 140 0 1998 Windows98 130 100 2000 WindowsME <:bv> 0 2009 90.1501647 109
  • 111. SQL> select yr 2 ,ver 3 ,bugs 4 ,est_bugs 5 from versions 6 where platform = 'Win' 7 model 8 dimension by (year as yr) 9 measures (ver,bugs, 0 est_bugs) 10 rules 11 ( 12 est_bugs[2009]= 13 ( select max(bugs) from versions ) 14 ); select yr * ERROR at line 1: ORA-32620: illegal subquery within MODEL rules 111
  • 112. SQL> select yr 2 ,ver 3 ,bugs 4 ,est_bugs 5 from versions 6 where platform = 'Win' 7 model 8 dimension by (year as yr) 9 measures (ver,bugs, 0 est_bugs, 10 ( select max(bugs) from versions ) x) 11 rules 12 ( 13 est_bugs[2009]= x[2000] 14 ); YR VER BUGS EST_BUGS ---------- ------------ ---------- ---------- 1995 Windows95 100 0 1998 Windows98 130 0 2002 WindowsXP 140 0 2000 WindowsME 170 0 2009 170 112
  • 114. SQL> select year 2 ,ver 3 ,bugs 4 ,est_bugs 5 from versions 6 where platform = 'Win' 7 model 8 dimension by (year) 9 measures (ver,bugs, 0 est_bugs) 10 rules 11 ( est_bugs[ANY]=bugs[CV()]*1.1 12 ) 13 / YEAR VER BUGS EST_BUGS ---------- --------------- ---------- ---------- 1995 Windows95 100 110 1998 Windows98 130 143 2000 WindowsME 170 187 2002 WindowsXP 140 154 114
  • 115. SQL> select year 2 ,ver 3 ,bugs 4 ,est_bugs 5 from versions 6 where platform = 'Win' 7 model 8 dimension by (year) 9 measures (ver,bugs, 0 est_bugs, 0 zero_bug) 10 rules 11 ( zero_bug[ANY]=CV()+10 12 ); ( zero_bug[ANY]=CV()+10 * ERROR at line 11: ORA-32611: incorrect use of MODEL CV operator 115
  • 116. SQL> select year 2 ,ver 3 ,bugs 4 ,est_bugs 5 ,zero_bug 6 from versions 7 where platform = 'Win' 8 model 9 dimension by (year) 10 measures (ver,bugs, 0 est_bugs, 0 zero_bug) 11 rules 12 ( zero_bug[ANY]=CV(YEAR)+10 13 ); YEAR VER BUGS EST_BUGS ZERO_BUG ---------- ------------ ---------- ---------- ---------- 1995 Windows95 100 0 2005 1998 Windows98 130 0 2008 2000 WindowsME 170 0 2010 2002 WindowsXP 140 0 2012 116
  • 118. SQL> select fib 2 from ( select rownum r from dual 3 connect by level <= 10 ) 4 model 5 dimension by (r) 6 measures (0 fib) 7 rules 8 ( fib[1]=1, 9 fib[2]=1, 10 fib[r>2]=fib[CV()-1]+fib[CV()-2] ); FIB ---------- 1 1 2 3 5 8 13 21 34 55 118
  • 121. SQL> select yr 2 ,ver 3 ,bugs 4 ,est_bugs 5 from versions 6 where platform = 'Win' 7 model 8 dimension by (year as yr) 9 measures (ver,bugs, 0 est_bugs) 10 rules 11 ( 12 est_bugs[2009]=100, 13 ver[2009]='Windows7' 14 ); YR VER BUGS EST_BUGS ---------- ------------ ---------- ---------- 1995 Windows95 100 0 1998 Windows98 130 0 2000 WindowsME 170 0 2002 WindowsXP 140 0 2009 Windows7 100 update or create a dimension value of '2009' 121
  • 122. SQL> select yr 2 ,ver 3 ,bugs 4 ,est_bugs 5 from versions 6 where platform = 'Win' 7 model 8 dimension by (year as yr) 9 measures (ver,bugs, 0 est_bugs) 10 rules 11 ( 12 est_bugs[yr=2009]=100, 13 ver[yr=2009]='Windows7' 14 ); YR VER BUGS EST_BUGS ---------- ------------ ---------- ---------- 1995 Windows95 100 0 1998 Windows98 130 0 2000 WindowsME 170 0 2002 WindowsXP 140 0 update if exists a dimension value of '2009' 122
  • 124. SQL> select yr 2 ,ver 3 ,bugs 4 ,est_bugs 5 from versions 6 where platform = 'Win' 7 model 8 dimension by (year as yr) 9 measures (ver,bugs, 0 est_bugs) 10 rules 11 ( 12 est_bugs[yr IN (2000,2009)]=100 13 ); YR VER BUGS EST_BUGS ---------- ------------ ---------- ---------- 1995 Windows95 100 0 1998 Windows98 130 0 2002 WindowsXP 140 0 2000 WindowsME 170 100 124
  • 125. SQL> select yr 2 ,ver 3 ,bugs 4 ,est_bugs 5 from versions 6 where platform = 'Win' 7 model 8 dimension by (year as yr) 9 measures (ver,bugs, 0 est_bugs) 10 rules 11 ( 12 est_bugs[FOR yr IN (2000,2009)]=100 13 ); YR VER BUGS EST_BUGS ---------- ------------ ---------- ---------- 1995 Windows95 100 0 1998 Windows98 130 0 2002 WindowsXP 140 0 2000 WindowsME 170 100 2009 100 125
  • 126. SQL> select yr 2 ,ver 3 ,bugs 4 ,est_bugs 5 from versions 6 where platform = 'Win' 7 model 8 dimension by (year as yr) 9 measures (ver,bugs, 0 est_bugs) 10 rules 11 ( 12 est_bugs[FOR yr FROM 2002 TO 2005 INCREMENT 1]=100 13 ); YR VER BUGS EST_BUGS ---------- ------------ ---------- ---------- 1995 Windows95 100 0 1998 Windows98 130 0 2000 WindowsME 170 0 2002 WindowsXP 140 100 2003 100 2004 100 2005 100 126
  • 127. SQL> select ... 7 model 8 dimension by (year as yr) 9 measures (ver,bugs, 0 est_bugs) 10 rules 11 ( 12 est_bugs[FOR yr IN 13 ( select year 14 from versions 15 where platform = 'Linux') ]=100 16 ); YR VER BUGS EST_BUGS ---------- ------------ ---------- ---------- 1995 Windows95 100 0 1998 Windows98 130 0 2000 WindowsME 170 0 2002 WindowsXP 140 0 1996 100 2006 100 2001 100 2003 100 127
  • 129. SQL> select yr 2 ,ver 3 ,bugs 4 ,est_bugs 5 from versions 6 where platform = 'Win' 7 model 8 dimension by (year as yr) 9 measures (ver,bugs, 0 est_bugs) 10 rules 11 ( 12 est_bugs[FOR yr IN (2000,2009)]=100, 13 ver[2009]='Windows7' ); YR VER BUGS EST_BUGS ---------- ------------ ---------- ---------- 1995 Windows95 100 0 1998 Windows98 130 0 2002 WindowsXP 140 0 2000 WindowsME 170 100 2009 Windows7 100 UPSERT 129
  • 130. SQL> select yr 2 ,ver 3 ,bugs 4 ,est_bugs 5 from versions 6 where platform = 'Win' 7 model 8 dimension by (year as yr) 9 measures (ver,bugs, 0 est_bugs) 10 rules UPDATE 11 ( 12 est_bugs[FOR yr IN (2000,2009)]=100, 13 ver[2009]='Windows7' ); YR VER BUGS EST_BUGS ---------- ------------ ---------- ---------- 1995 Windows95 100 0 1998 Windows98 130 0 2002 WindowsXP 140 0 2000 WindowsME 170 100 2009 Windows7 100 2009 gone 130
  • 131. idiosyncracies # 2 the "sert" in upsert 131
  • 132. SQL> select * 2 from versions 3 where platform = 'z/OS'; no rows selected SQL> select * 2 from versions 3 where platform = 'z/OS' 4 model 5 dimension by (year as yr) 6 measures (ver, 0 est_bugs) 7 rules 8 ( est_bugs[FOR yr IN (2000,2002,2009)]=100, 9 ver[ANY]='IBM' ); YR VER EST_BUGS ---------- --------------- ---------- 2000 IBM 100 2002 IBM 100 2009 IBM 100 132
  • 135. SQL> select yr 2 ,ver 3 ,bugs 4 ,est_bugs 5 from versions 6 where platform = 'Win' 7 model 8 dimension by (year as yr) 9 measures (ver,bugs, 0 est_bugs, year as yr2) 10 rules 11 ( 12 yr2[ANY]=yr2[CV()]-2, 13 est_bugs[yr2[2000]]=100 14 ); YR VER BUGS EST_BUGS ---------- ------------ ---------- ---------- 1995 Windows95 100 0 1998 Windows98 130 100 2000 WindowsME 170 0 2002 WindowsXP 140 0 yr2[2000]=2000-2=1998 est_bugs[1998]=100 135
  • 136. most typical SQL applies 136
  • 137. SQL> select ... 7 model 8 dimension by (year as yr) 9 measures (ver,bugs, 0 est_bugs) 10 rules 11 ( 12 est_bugs[yr is null]=100, 13 est_bugs[yr is not null]=110, 14 est_bugs[yr > 0]=120, 15 est_bugs[yr between 2000 and 2010]=130, 16 est_bugs[null]=140 17 ); YR VER BUGS EST_BUGS ---------- ------------ ---------- ---------- 1995 Windows95 100 120 1998 Windows98 130 120 2000 WindowsME 170 130 2002 WindowsXP 140 130 (null) 140 137
  • 139. SQL> select year 2 ,ver 3 ,bugs 4 ,est_bugs 5 from versions 6 model 7 dimension by (platform,year) 8 measures (ver,bugs, 0 est_bugs) 9 rules 10 ( 11 est_bugs[2009]=100 12 ); est_bugs[2009]=100 * ERROR at line 11: ORA-00947: not enough values 139
  • 140. SQL> select year 2 ,ver 3 ,bugs 4 ,est_bugs 5 from versions 6 where platform = 'Win' 7 model 8 dimension by (year) 9 measures (ver,bugs, 0 est_bugs) 10 rules 11 ( 12 est_bugs['Win',2009]=100 13 ); est_bugs['Win',2009]=100 * ERROR at line 12: ORA-00947: not enough values 140
  • 142. SQL> select year 2 ,ver 3 ,bugs 4 ,cumtot 5 from versions 6 where platform = 'Win' 7 model 8 dimension by (year) 9 measures (ver,bugs, 0 cumtot) 10 rules 11 ( cumtot[ANY]=SUM(bugs)[year <= CV(year)] 12 ); YEAR VER BUGS CUMTOT ---------- ------------ ---------- ---------- 1995 Windows95 100 100 1998 Windows98 130 230 2000 WindowsME 170 400 2002 WindowsXP 140 540 142
  • 143. SQL> select year 2 ,ver 3 ,bugs 4 ,wt 5 from versions 6 where platform = 'Win' 7 model 8 dimension by (year) 9 measures (ver,bugs, 0 wt) 10 rules 11 ( wt[ANY]=bugs[CV()]* 12 row_number() over ( order by year ) 13 ); YEAR VER BUGS WT ---------- ------------ ---------- ---------- 1995 Windows95 100 100 1998 Windows98 130 260 2000 WindowsME 170 510 2002 WindowsXP 140 560 143
  • 145. SQL> select year 2 ,ver 3 ,bugs 4 from versions 5 where platform = 'Win' 6 model 7 dimension by (year) 8 measures (ver,bugs) 9 rules automatic order 10 ( bugs[2000]=150, 11 bugs[ANY]=bugs[CV()]*1.1 12 ) 13 / bugs[ANY]=bugs[CV()]*1.1 * ERROR at line 11: ORA-32630: multiple assignment in automatic order MODEL 145
  • 146. SQL> select year 2 ,ver 3 ,bugs 4 from versions 5 where platform = 'Win' 6 model 7 dimension by (year) 8 measures (ver,bugs) 9 rules sequential order 10 ( bugs[2000]=150, 11 bugs[ANY]=bugs[CV()]*1.1 12 ) 13 / YEAR VER BUGS ---------- --------------- ---------- 1995 Windows95 110 1998 Windows98 143 2000 WindowsME 165 2002 WindowsXP 154 146
  • 147. SQL> select year 2 ,ver 3 ,bugs 4 from versions 5 where platform = 'Win' 6 model 7 dimension by (year) 8 measures (ver,bugs) 9 rules sequential order 10 ( bugs[ANY]=bugs[CV()]*1.1, 11 bugs[2000]=150 12 ) 13 / YEAR VER BUGS ---------- --------------- ---------- 1995 Windows95 110 1998 Windows98 143 2000 WindowsME 150 2002 WindowsXP 154 110 143 165 154 147
  • 148. rule affected rows only 148
  • 149. SQL> select year 2 ,ver 3 ,bugs 4 from versions 5 where platform = 'Win' 6 model return updated rows 7 dimension by (year) 8 measures (ver,bugs) 9 rules 10 ( ver[2009]='Windows7', 11 bugs[2009]=150 12 ) 13 / YEAR VER BUGS ---------- --------------- ---------- 2009 Windows7 150 149
  • 151. 151
  • 152. SQL> select year 2 ,ver 3 ,bugs 4 ,est_bugs 5 from versions 6 where platform = 'Win' 7 model 8 dimension by (year) 9 measures (ver,bugs, 0 est_bugs) 10 rules 11 ( est_bugs[ANY]=bugs[CV()-1]*1.1 12 ) 13 / YEAR VER BUGS EST_BUGS ---------- --------------- ---------- ---------- 1995 Windows95 100 1998 Windows98 130 2000 WindowsME 170 2002 WindowsXP 140 est_bugs[1995]=bugs[1994] est_bugs[1998]=bugs[1997] est_bugs[2000]=bugs[1999] est_bugs[2002]=bugs[2001] 152
  • 154. SQL> select rank() over ( order by year) as year_rank 2 ,year 3 ,ver 4 ,bugs 5 from versions 6 where platform = 'Win' 7 / YEAR_RANK YEAR VER BUGS ---------- ---------- --------------- ---------- 1 1995 Windows95 100 2 1998 Windows98 130 3 2000 WindowsME 170 4 2002 WindowsXP 140 154
  • 155. SQL> select year_rank,year 2 ,ver,bugs,est_bugs 3 from versions 4 where platform = 'Win' 5 model 6 dimension by ( 7 rank() over ( order by year) as year_rank) 8 measures (ver,bugs,year,0 est_bugs) 9 rules 10 ( est_bugs[1]=bugs[1], 11 est_bugs[year_rank > 1]=bugs[CV()-1]*1.1 12 ); YEAR_RANK YEAR VER BUGS EST_BUGS ---------- ---------- --------------- ---------- ---------- 1 1995 Windows95 100 100 2 1998 Windows98 130 110 3 2000 WindowsME 170 143 4 2002 WindowsXP 140 187 155
  • 157. 157
  • 158. 158
  • 159. SQL> select year_rank,year 2 ,ver,bugs,est_bugs 3 from versions 4 where platform = 'Win' 5 model 6 dimension by ( 7 rank() over ( order by year) as year_rank) 8 measures (ver,bugs,year,0 est_bugs) 9 rules 10 ( est_bugs[1]=bugs[1], 11 est_bugs[year_rank > 1]=bugs[CV()-1]*1.1 12 ); YEAR_RANK YEAR VER BUGS EST_BUGS ---------- ---------- --------------- ---------- ---------- 1 1995 Windows95 100 100 2 1998 Windows98 130 110 3 2000 WindowsME 170 143 4 2002 WindowsXP 140 187 159
  • 160. SQL> select year_rank,year 2 ,ver,bugs,est_bugs 3 from versions 4 where platform = 'Win' 5 model 6 dimension by ( 7 rank() over ( order by year) as year_rank) 8 measures (ver,bugs,year,0 est_bugs) 9 rules 10 ( est_bugs[ANY]=bugs[CV()-1]*1.1 11 ); YEAR_RANK YEAR VER BUGS EST_BUGS ---------- ---------- --------------- ---------- ---------- 1 1995 Windows95 100 2 1998 Windows98 130 110 3 2000 WindowsME 170 143 4 2002 WindowsXP 140 187 160
  • 161. but can be overridden 161
  • 162. SQL> select year_rank,year 2 ,ver,bugs,est_bugs 3 from versions 4 where platform = 'Win' 5 model IGNORE NAV 6 dimension by ( 7 rank() over ( order by year) as year_rank) 8 measures (ver,bugs,year,0 est_bugs) 9 rules 10 ( est_bugs[ANY]=bugs[CV()-1]*1.1 11 ); YEAR_RANK YEAR VER BUGS EST_BUGS ---------- ---------- --------------- ---------- ---------- 1 1995 Windows95 100 0 2 1998 Windows98 130 110 3 2000 WindowsME 170 143 4 2002 WindowsXP 140 187 162
  • 163. SQL> select * 2 from dual 3 where 1=0 4 model ignore nav 5 dimension by (0 tag) 6 measures (to_date(null) d, 7 to_number(null) n, 8 cast(null as varchar2(10)) v) 9 rules 10 ( d[0] = d[1], 11 n[0] = n[1], 12 v[0] = v[1] 13 ); TAG D N V ---------- ------------------- ---------- ------ 0 01/01/2000 00:00:00 0 dimension 1 does not exist beware documentation ! 163
  • 164. useful for cascading measures 164
  • 165. SQL> select year_rank,year 2 ,ver,bugs,cum_bugs 3 from versions 4 where platform = 'Win' 5 model 6 dimension by ( 7 rank() over ( order by year) as year_rank) 8 measures (ver,bugs,year,to_number(null) cum_bugs) 9 rules 10 ( cum_bugs[ANY]=cum_bugs[CV()-1]+bugs[CV()-1] 11 ); YEAR_RANK YEAR VER BUGS CUM_BUGS ---------- ---------- --------------- ---------- ---------- 1 1995 Windows95 100 2 1998 Windows98 130 3 2000 WindowsME 170 4 2002 WindowsXP 140 165
  • 166. SQL> select year_rank,year 2 ,ver,bugs,cum_bugs 3 from versions 4 where platform = 'Win' 5 model IGNORE NAV 6 dimension by ( 7 rank() over ( order by year) as year_rank) 8 measures (ver,bugs,year,to_number(null) cum_bugs) 9 rules 10 ( cum_bugs[ANY]=cum_bugs[CV()-1]+bugs[CV()-1] 11 ); YEAR_RANK YEAR VER BUGS EST_BUGS ---------- ---------- --------------- ---------- ---------- 1 1995 Windows95 100 0 2 1998 Windows98 130 100 3 2000 WindowsME 170 230 4 2002 WindowsXP 140 400 166
  • 168. SQL> select ... 6 from versions 7 where platform = 'Win' 8 model 9 dimension by (rank() over ( order by year) as year_rank) 10 measures (ver,bugs,year,bugs est_bugs) 11 rules 12 ( 13 est_bugs[ANY]=est_bugs[CV()-1]*1.1 14 ); YEAR_RANK YEAR VER BUGS EST_BUGS ---------- ---------- ------------ ---------- ---------- 1 1995 Windows95 100 2 1998 Windows98 130 3 2000 WindowsME 170 4 2002 WindowsXP 140 168
  • 169. SQL> select ... 6 from versions 7 where platform = 'Win' 8 model 9 dimension by (rank() over ( order by year) as year_rank) 10 measures (ver,bugs,year,bugs est_bugs) 11 rules 12 ( 13 est_bugs[ANY] order by year_rank desc = 14 est_bugs[CV()-1]*1.1 15 ); YEAR_RANK YEAR VER BUGS EST_BUGS ---------- ---------- ------------ ---------- ---------- 1 1995 Windows95 100 2 1998 Windows98 130 110 3 2000 WindowsME 170 143 4 2002 WindowsXP 140 187 169
  • 170. lots of null "variations" column is null dimension does not exist ignore nav / keep nav 170
  • 171. SQL> select year, ver, bugs, patches 2 from versions 3 where platform = 'Win'; YEAR VER BUGS PATCHES ---------- --------------- ---------- ---------- 1994 Windows3.1.1 140 1995 Windows95 100 1998 Windows98 130 2000 WindowsME 170 2002 WindowsXP 140 3 2003 Windows2003 140 1 FCAST ---------- (null) (null) (null) (null) (null) 110 "forecast = bugs(year-1) – 10*patches(year-1)" 171
  • 172. SQL> select year, ver, patches, fcast, pv, pnv 2 from versions 3 where platform = 'Win' 4 model 5 dimension by ( year ) 6 measures (ver, bugs, 0 fcast, patches, 'X' pv, 'X' pnv) 7 rules 8 ( 9 fcast[ANY]=bugs[CV()]-10*patches[CV()-1], 10 pv[ANY]=PRESENTV( patches[CV()-1], 'Y','N'), 11 pnv[ANY]=PRESENTNNV( patches[CV()-1], 'Y','N') 12 ); YEAR VER PATCHES FCAST PV PNV ---------- --------------- ---------- ---------- ---- ---- 1994 Windows3.1.1 N N 1995 Windows95 Y N 1998 Windows98 N N 2000 WindowsME N N 2002 WindowsXP 3 N N 2003 Windows2003 1 110 Y Y 172
  • 173. "duh...I know about NVL" resultset time rule execution time 173
  • 175. "if the number of bugs drops by 4% each year, what is the 5 year forecast for each product" Windows XP 140 Windows XP 134 Windows XP 129 Windows XP 123 Windows XP 118 Windows XP 113 175
  • 176. SQL> select year, ver, bugs, bugs5yr 2 from versions 3 where platform = 'Win' 4 model 5 dimension by ( year ) 6 measures (ver, bugs, bugs bugs5yr) 7 rules ITERATE(5) 8 ( 9 bugs5yr[ANY]=bugs5yr[CV()] * 0.96 10 ); YEAR VER BUGS BUGS5YR ---------- --------------- ---------- ------- 1995 Windows95 100 81.54 1998 Windows98 130 106.00 2000 WindowsME 170 138.61 2002 WindowsXP 140 114.15 176
  • 177. 5 iterations per partition 177
  • 179. SQL> select num 2 from dual 3 model 4 dimension by ( 0 x) 5 measures ( 0 num) 6 rules iterate (20) 7 ( 8 num[ITERATION_NUMBER]=ITERATION_NUMBER 9 ); NUM ---------- 0 1 2 3 4 ... 17 18 19 20 rows selected. starts from zero 179
  • 182. SQL> select * 2 from loans; DESCR YEAR BAL RATE PMT ---------- ---------- ---------- ---------- ---------- Car 2000 25000 1.13 350 House 2010 300000 1.04 2200 182
  • 183. SQL> select descr, bal final_bal, yrs 2 from loans 3 model 4 partition by ( year) 5 dimension by (0 idx) 6 measures (descr, bal, rate, pmt, 0 yrs) 7 rules iterate (50) until bal[0]*rate[0]-12*pmt[0]<0 8 ( 9 bal[0]=bal[0]*rate[0]-12*pmt[0] 10 ,yrs[0]=iteration_number 11 ); DESCR FINAL_BAL YRS ---------- ----------- ---------- House 11660.34 14 Car 632.33 11 183
  • 185. "how many years will it take for my house to appreciate in value more than my annual mortgage payments" 185
  • 186. SQL> select year, bal, apprec, yrs 2 from loans 3 where descr = 'House' 4 model 5 partition by ( year ) 6 dimension by ( 0 idx) 7 measures ( year y, bal, 12*pmt mort, apprec, 0 yrs) 8 rules iterate (20) 9 until bal[0]- previous( bal[0] ) > mort[0] 10 ( 11 bal[0]=bal[0]*(1+apprec[0]/100), 12 yrs[0]=iteration_number+1 13 ); YEAR BAL APPREC YRS ---------- ---------- --------- ---------- 2010 437742.689 6.5 6 186
  • 188. SQL> select * from VERSIONS; PLATFORM YEAR VER BUGS ---------- ---------- --------------- ---------- Win 1995 Windows95 100 Win 1998 Windows98 130 Win 2000 WindowsME 170 Win 2002 WindowsXP 140 Linux 1996 RedHat 50 Linux 2006 Oracle 80 Linux 2001 SUSE 65 Linux 2003 CentOS 90 SQL> select * from PLATFORM_TYPE; PLATFORM OWNERSHIP -------------------- -------------------- Win Private Linux Open Source 188
  • 189. SQL> select year, ver, bugs, est_bugs, own_ship 2 from versions 3 model 4 reference pt on 5 ( select platform p, ownership own 6 from platform_type ) 7 dimension by (p) 8 measures (own) 9 dimension by (year) 10 measures (ver,bugs, 0 est_bugs, 11 platform, cast(null as varchar2(20)) own_ship) 12 rules 13 ( est_bugs[1995]=bugs[1995], 14 est_bugs[year > 1995]=bugs[cv()]*1.1, 15 own_ship[any]=pt.own[platform[cv()]] 16 ); YEAR VER BUGS EST_BUGS OWN_SHIP ---------- --------------- ---------- ---------- ----------- 1995 Windows95 100 100 Private 1998 Windows98 130 143 Private 2000 WindowsME 170 187 Private 2002 WindowsXP 140 154 Private 1996 RedHat 50 55 Open Source 2006 Oracle 80 88 Open Source 2001 SUSE 65 71.5 Open Source 2003 CentOS 90 99 Open Source189
  • 190. why not just a join ? 190
  • 191. “imagination is more important than knowledge” - Albert Einstein 191
  • 193. SQL> create table DEC as 2 select rownum r 3 from dual connect by level < 1000; Table created. SQL> select * from DEC; R ---------- 1 2 3 4 5 6 7 8 9 10 193
  • 194. SQL> select r, ltrim(str,'0') 2 from DEC 3 model 4 dimension by (r) 5 measures ( 6 cast('' as varchar2(64)) str, 7 r as runtot, 8 power(2,32) as chk) 9 rules iterate(33) 10 ( str[ANY] = 11 str[CV()] || 12 case 13 when bitand(runtot[CV()],chk[CV()]) > 0 14 then '1' else '0' 15 end, 16 runtot[ANY] = 17 runtot[CV()] - 18 bitand(runtot[CV()],chk[CV()]), 19 chk[ANY] = chk[CV()] / 2 20 ); 194
  • 195. R BITSTR -------- ----------------- 1 1 2 10 3 11 4 100 5 101 6 110 7 111 8 1000 9 1001 10 1010 11 1011 12 1100 13 1101 14 1110 15 1111 16 10000 17 10001 18 10010 195
  • 197. select r, ltrim(str,'0') from DEC model partition by (r) dimension by (1 blah) measures ( cast('' as varchar2(64)) str, r as runtot, power(2,32) as chk) rules iterate(33) ( str[1] = str[1] || case when bitand(runtot[1],chk[1]) > 0 then '1' else '0' end, runtot[1] = runtot[1] - bitand(runtot[1],chk[1]), chk[1] = chk[1] / 2 ); 197
  • 199. SQL> select e1.ename, e2.ename manager, e1.sal, e1.comm 2 from emp e1, emp e2 3 where e1.mgr= e2.empno; ENAME MANAGER SAL COMM ---------- ---------- ---------- ---------- JONES KING 2975 CLARK KING 2450 BLAKE KING 2850 WARD BLAKE 1250 500 JAMES BLAKE 950 TURNER BLAKE 1500 0 ALLEN BLAKE 1600 300 MARTIN BLAKE 1250 1400 199
  • 200. SQL> select ename, manager, sal, comm 2 from emp 3 model 4 dimension by (empno) 5 measures (ename, mgr, sal, comm, 6 cast (null as varchar2(10)) as manager) 7 rules ( 8 manager[any] = ename[mgr[cv()]] 9 ); ENAME MANAGER SAL COMM ---------- ---------- ---------- ---------- KING ALLEN 5000 BLAKE KING 2850 CLARK KING 2450 JONES KING 2975 MARTIN BLAKE 1250 1400 ALLEN BLAKE 1600 300 ... 200
  • 202. SQL> select deptno, ltrim(str,',') str 2 from emp 3 model return updated rows 4 partition by (deptno) 5 dimension by ( 6 rank() over ( partition by deptno order by empno) x ) 7 measures ( ename, cast('' as varchar2(4000)) str) 8 rules iterate (20) 9 until presentv(ename[iteration_number+1],1,2)=2 10 ( 11 str[1] = str[1] || ','|| ename[iteration_number+1] 12 ); DEPTNO STR ---------- ------------------------------------------------- 20 SMITH,JONES,SCOTT,ADAMS,FORD, 10 CLARK,KING,MILLER, 30 ALLEN,WARD,MARTIN,BLAKE,TURNER,JAMES, 202
  • 204. SQL> select 2 col1, 3 col2, 4 my_function(...) 5 from EMP; 204
  • 208. SELECT c, p, m, pp, ip FROM MORTGAGE MODEL REFERENCE R ON (SELECT customer, fact, amt FROM mortgage_facts MODEL DIMENSION BY (customer, fact) MEASURES (amount amt) RULES (amt[any, 'PaymentAmt']= (amt[CV(),'Loan']* Power(1+ (amt[CV(),'Annual_Interest']/100/12), amt[CV(),'Payments']) * (amt[CV(),'Annual_Interest']/100/12)) / (Power(1+(amt[CV(),'Annual_Interest']/100/12), amt[CV(),'Payments']) - 1))) DIMENSION BY (customer cust, fact) measures (amt) MAIN amortization PARTITION BY (customer c) DIMENSION BY (0 p) MEASURES (principalp pp, interestp ip, mort_balance m, customer mc) RULES ITERATE(1000) UNTIL (ITERATION_NUMBER+1 =r.amt[mc[0],'Payments']) (ip[ITERATION_NUMBER+1] = m[CV()-1] * r.amt[mc[0], 'Annual_Interest']/1200, pp[ITERATION_NUMBER+1] = r.amt[mc[0], 'PaymentAmt'] - ip[CV()], m[ITERATION_NUMBER+1] = m[CV()-1] - pp[CV()] ) 208
  • 209. 209
  • 211. you cannot kill Excel 211
  • 213. all the work formulas layout rules lookups 213