the model clause
DESCRIPTION
The Model Clause. A case study at E.On. Introduction. [email protected]. A little about me, the company I work for, the team I work in and today’s presentation. A brief introduction to the model clause. Example statement:. select empno , ename , sal from emp where deptno = 10 - PowerPoint PPT PresentationTRANSCRIPT
![Page 1: The Model Clause](https://reader031.vdocument.in/reader031/viewer/2022013004/568145f5550346895db2fddf/html5/thumbnails/1.jpg)
The Model Clause
A case study at E.On
![Page 2: The Model Clause](https://reader031.vdocument.in/reader031/viewer/2022013004/568145f5550346895db2fddf/html5/thumbnails/2.jpg)
Introduction
2
A little about me, the company I work for, the team I work in and today’s presentation.
![Page 3: The Model Clause](https://reader031.vdocument.in/reader031/viewer/2022013004/568145f5550346895db2fddf/html5/thumbnails/3.jpg)
A brief introduction to the model clause
Example statement:
3
http://docs.oracle.com/cd/B28359_01/server.111/b28313/sqlmodel.htm
select empno, ename, salfrom empwheredeptno = 10
MODELdimension by (empno)measures (ename, sal)rules ()
/
![Page 4: The Model Clause](https://reader031.vdocument.in/reader031/viewer/2022013004/568145f5550346895db2fddf/html5/thumbnails/4.jpg)
4
Scenario 1: Quarterly Critical Patch Updates
![Page 5: The Model Clause](https://reader031.vdocument.in/reader031/viewer/2022013004/568145f5550346895db2fddf/html5/thumbnails/5.jpg)
5
SID Primary host
Standby host
orcl1 box1 box3
orcl2 box3 box4
orcl3 box4 none
orcl4 box4 box5
orcl5 box2 box1
orcl6 box6 none
orcl7 box7 box6
orcl8 box8 none
![Page 6: The Model Clause](https://reader031.vdocument.in/reader031/viewer/2022013004/568145f5550346895db2fddf/html5/thumbnails/6.jpg)
6
create table lod (sid varchar2(20), host varchar2(20), dbrole varchar2(10));
insert into lod values ('orcl1','box1','prmy');insert into lod values ('orcl1','box3','stby');insert into lod values ('orcl2','box3','prmy');insert into lod values ('orcl2','box4','stby');insert into lod values ('orcl3','box4','prmy');insert into lod values ('orcl4','box4','stby');insert into lod values ('orcl4','box5','prmy');insert into lod values ('orcl5','box2','prmy');insert into lod values ('orcl5','box1','stby');insert into lod values ('orcl6','box6','prmy');insert into lod values ('orcl7','box7','prmy');insert into lod values ('orcl7','box6','stby');insert into lod values ('orcl8','box8','prmy');
commit;
var n numberbeginselect count(*) into :n from lod;end;/
![Page 7: The Model Clause](https://reader031.vdocument.in/reader031/viewer/2022013004/568145f5550346895db2fddf/html5/thumbnails/7.jpg)
7
select clump, sid, host, dbrole, rnfrom lodmodeldimension by (sid, host, dbrole)measures (rownum as clump,rownum as rn)rulesiterate(10000) until (iteration_number =:n) (--update clumps for the hosts to the lowest value currently for identical hostsclump[any,host,any]=least
(nvl(min(clump) over (partition by host order by clump rows
between unbounded preceding and unbounded following),:n))
,--update clump for the sids to be the lowest of current clump valuesclump[any,host,any]=least
(nvl(min(clump) over (partition by sid order by clump rows between
unbounded preceding and unbounded following),:n))
)/
![Page 8: The Model Clause](https://reader031.vdocument.in/reader031/viewer/2022013004/568145f5550346895db2fddf/html5/thumbnails/8.jpg)
8
Intermediate step.
![Page 9: The Model Clause](https://reader031.vdocument.in/reader031/viewer/2022013004/568145f5550346895db2fddf/html5/thumbnails/9.jpg)
9
Intermediate step.
![Page 10: The Model Clause](https://reader031.vdocument.in/reader031/viewer/2022013004/568145f5550346895db2fddf/html5/thumbnails/10.jpg)
10
Intermediate step.
![Page 11: The Model Clause](https://reader031.vdocument.in/reader031/viewer/2022013004/568145f5550346895db2fddf/html5/thumbnails/11.jpg)
11
Final output.
![Page 12: The Model Clause](https://reader031.vdocument.in/reader031/viewer/2022013004/568145f5550346895db2fddf/html5/thumbnails/12.jpg)
12
alter table lod add (version varchar2(20) default '10g');
update lod set version ='11g' where sid = 'orcl2';commit;
The previous example was simplified, here we also take into account Oracle version
![Page 13: The Model Clause](https://reader031.vdocument.in/reader031/viewer/2022013004/568145f5550346895db2fddf/html5/thumbnails/13.jpg)
13
select version, clump, sid, host, dbrole, rnfrom lodMODELpartition by (version)dimension by (sid, host, dbrole)measures (rownum as clump,rownum as rn)rulesiterate(10000) until (iteration_number =:n) (--update clumps for the hosts to the lowest value currently for identical hostsclump[any,host,any]=least
(nvl(min(clump) over (partition by host order by clump rows
between unbounded preceding and unbounded following),:n))
,--update clump for the sids to be the lowest of current clump valuesclump[any,host,any]=least
(nvl(min(clump) over (partition by sid order by clump rows between
unbounded preceding and unbounded following),:n))
)order by clump/
![Page 14: The Model Clause](https://reader031.vdocument.in/reader031/viewer/2022013004/568145f5550346895db2fddf/html5/thumbnails/14.jpg)
14
![Page 15: The Model Clause](https://reader031.vdocument.in/reader031/viewer/2022013004/568145f5550346895db2fddf/html5/thumbnails/15.jpg)
Scenario 2: Missing data in a time-series
15
Original requirement arose during a project to investigate whether objects are being used.
![Page 16: The Model Clause](https://reader031.vdocument.in/reader031/viewer/2022013004/568145f5550346895db2fddf/html5/thumbnails/16.jpg)
16
![Page 17: The Model Clause](https://reader031.vdocument.in/reader031/viewer/2022013004/568145f5550346895db2fddf/html5/thumbnails/17.jpg)
17
desc dbm_apps.monitor_usage_aud@gfcspw01
![Page 18: The Model Clause](https://reader031.vdocument.in/reader031/viewer/2022013004/568145f5550346895db2fddf/html5/thumbnails/18.jpg)
18
![Page 19: The Model Clause](https://reader031.vdocument.in/reader031/viewer/2022013004/568145f5550346895db2fddf/html5/thumbnails/19.jpg)
19
![Page 20: The Model Clause](https://reader031.vdocument.in/reader031/viewer/2022013004/568145f5550346895db2fddf/html5/thumbnails/20.jpg)
20
with data as(select day as orig_day, value,day start_dt, nvl(lag(day) over (order by day desc nulls last),day)-1 end_dtfrom (select trunc(datefield) as day, count(*) as value from dbm_apps.monitor_usage_aud@gfcspw01group by trunc(datefield))order by day)select value as quantity,s2 as time_periodfrom dataMODEL partition by (orig_day, start_dt, end_dt) dimension by (0 as z) measures (1 x,value, start_dt s2, end_dt e2) rules sequential order iterate (5) until ( previous(s2[ITERATION_NUMBER]) >= previous(e2[ITERATION_NUMBER]) )(x[ITERATION_NUMBER]=ITERATION_NUMBER,s2[ITERATION_NUMBER]=cv(start_dt)+ITERATION_NUMBER,e2[ITERATION_NUMBER]=cv(end_dt))order by s2, value
![Page 21: The Model Clause](https://reader031.vdocument.in/reader031/viewer/2022013004/568145f5550346895db2fddf/html5/thumbnails/21.jpg)
Scenario 3: team rota
21
There is a need for our team assignments to be easily visible to both ourselves and our customers. We also need to make sure that resource has been assigned.
![Page 22: The Model Clause](https://reader031.vdocument.in/reader031/viewer/2022013004/568145f5550346895db2fddf/html5/thumbnails/22.jpg)
22
![Page 23: The Model Clause](https://reader031.vdocument.in/reader031/viewer/2022013004/568145f5550346895db2fddf/html5/thumbnails/23.jpg)
23
![Page 24: The Model Clause](https://reader031.vdocument.in/reader031/viewer/2022013004/568145f5550346895db2fddf/html5/thumbnails/24.jpg)
24
![Page 25: The Model Clause](https://reader031.vdocument.in/reader031/viewer/2022013004/568145f5550346895db2fddf/html5/thumbnails/25.jpg)
25
create table pp_rota(DUTY VARCHAR2(20),PERSON NOT NULL VARCHAR2(20),WHEN DATE)/
![Page 26: The Model Clause](https://reader031.vdocument.in/reader031/viewer/2022013004/568145f5550346895db2fddf/html5/thumbnails/26.jpg)
26
select when , duty||'.'||person, duty, decode(person,'MISSING',null,person) as real_personfrom pp_rotamodelpartition by (when)dimension by (duty)measures (person)rules (person['livebuild']=nvl(person[cv(duty)],'MISSING'),person['backflush']=nvl(person[cv(duty)],'MISSING'),person['systest']=nvl(person[cv(duty)],'MISSING'),person['ep']=nvl(person[cv(duty)],'MISSING'))order by when, duty
![Page 27: The Model Clause](https://reader031.vdocument.in/reader031/viewer/2022013004/568145f5550346895db2fddf/html5/thumbnails/27.jpg)
Wrap up...
27