SlideShare une entreprise Scribd logo
1  sur  47
Télécharger pour lire hors ligne
Data warehouse Design Using Oracle
https://www.oercommons.org/authorin
g/edit/21861
Dr. Girija Narasimhan 1
OER- UNIT 5 SQL MODEL CLAUSE
Part 1- SQL model clause
2
Dr. Girija Narasimhan
Model Clause
3
Dr. Girija Narasimhan
Model Clause
With the SQL model clause you build one or more
matrixes with a variable number of dimensions. This is
called the model.
The model uses a subset of the available columns from
your FROM clause.
It contains at least one dimension, at least one measure
and optionally one or more partitions
create table salesorder(ord number(4) primary key,prodno
number(3),suppno number(3),time number(5),location
varchar2(20),sales number(6));
4
Dr. Girija Narasimhan
Model Clause
Ord Prodno Suppno Time Location sales
1 1 1 2000 Sohar 5
2 1 1 2000 Muscat 3
3 1 1 2001 Sohar 6
4 1 1 2001 Muscat 4
5 1 2 2000 Sohar 1
6 1 2 2000 Muscat 7
7 1 2 2001 Sohar 8
8 1 2 2001 Musat 5
9 2 1 2000 Sohar 3
10 2 1 2000 Muscat 8
11 2 1 2001 Sohar 6
12 2 1 2001 Muscat 7
13 2 2 2000 Sohar 9
14 2 2 2000 Muscat 11
15 2 2 2001 Sohar 4
16 2 2 2001 Muscat 3
5
Dr. Girija Narasimhan
Model Clause
Partition columns
Partition columns divide the result set into blocks. Rules defined
in the model clause are applied independently of other
partitions to each partition.
Dimension columns
Dimension columns define how cells within a partition can be
accessed.
Measure columns
The columns defined as measures can be assigned new values
in the rules section of the model clause.
6
Dr. Girija Narasimhan
Model Clause
Part 2- Dimension by
Unique column
Dr. Girija Narasimhan
Model Clause
7
Dimension by
Unique
column
Multi dimension
column
Aliasing Expression
Dr. Girija Narasimhan
Model Clause
8
In the model clause, the dimension components
are used to define multi-dimension array and it
is also useful for identifying cells or column
within the partition.
By default it will identify at least one cell in a
partition
The dimension components have the column name
which has unique value
Dr. Girija Narasimhan
Model Clause
9
Query Output
Select ord, sales from salesorder
Where time=2000
model
dimension by(ord)
measures(sales)
rules()
order by ord;
ORD SALES
---------- ----------
1 5
2 3
5 1
6 7
9 3
10 8
13 9
14 11
8 rows selected.
Dr. Girija Narasimhan
Model Clause
10
Column value given in the dimension is not unique
then it will give "non unique addressing" error.
Dr. Girija Narasimhan
Model Clause
11
Part 3- Dimension by
Multiple dimension using
unique keys
Dr. Girija Narasimhan
Model Clause
12
It is possible to use more than one dimension column be
specified.
But all the combination gives the unique row identification
Dr. Girija Narasimhan
Model Clause
13
Part 4- Dimension by
aliasing
Dr. Girija Narasimhan
Model Clause
14
In the result set, the user desired column name can be
displayed by using aliasing "as" in the dimension.
Dr. Girija Narasimhan
Model Clause
15
Part 5- Dimension by
Expression
Dr. Girija Narasimhan
Model Clause
16
It is possible to use expression in the dimension component.
In the given query, value of the ord column is multiplied by 10. So,
column value 3 is displaying as 30.
Dr. Girija Narasimhan
Model Clause
17
Part 6-sql model clause
Measures
Dr. Girija Narasimhan
Model Clause
18
Measure is a data column of the table.
It is similar to measure in the star schema based
fact table.
Generally measures have numeric based values
like cost or amount.
Each cell or column mentioned in the measures is
accessed by specifying its full combination of
dimensions.
Dr. Girija Narasimhan
Model Clause
19
Dr. Girija Narasimhan
Model Clause
20
Like dimension it is possible to write expression in the
measure column also.
Dr. Girija Narasimhan
Model Clause
21
Part 7-sql model clause
Partition by
Dr. Girija Narasimhan
Model Clause
22
The Oracle data warehousing describes
partition as a logical block of the result set.
It is similar to how partition in the
analytical functions.
Each partition is viewed by the formula
mentioned in the partition by component
and treated as an independent array.
Dr. Girija Narasimhan
Model Clause
23
Dr. Girija Narasimhan
Model Clause
24
Part 8-sql model clause
Rules
Dr. Girija Narasimhan
Model Clause
25
In the model clause, rules hold the expressions that
assign values to measures.
A rule is an assignment statement whose left side
represents a cell or a range of cells and whose right
side is an expression involving constants, bind
variables or individual cell or aggregate function.
There are three terms used in rules namely
cell reference, dimension reference, cell assignment.
Dr. Girija Narasimhan
Model Clause
26
Dr. Girija Narasimhan
Model Clause
27
The term "newsal" is called a "cell reference, Cell references (i.e
newsal) can only refer to measure cells, not dimension cells.
The dimension reference is part between the square bracket [] in
the cell reference
When a cell reference is used as the assignment target on the
left side of a rule equation is called cell assignment.
newsal[1]=100
Cell reference ,it
refers measures
Dimension
reference
Cell
Assignment
Dr. Girija Narasimhan
Model Clause
28
Part 9-sql model clause
Rules
create new row
Dr. Girija Narasimhan
Model Clause
29
The RULES clause also used to create
new rows in the result set
Dr. Girija Narasimhan
Model Clause
30
Adding values to newly created row
It is also possible to add values to newly
created row by using Rules Clause
Query Result
Select ord,time,sales from
salesorder
Where location=’Sohar’ and
prodno=1
Model
dimension by(ord)
Measures(time,sales)
Rules(time[17]=2002,sales[17]=8);
ORD TIME SALES
---------- ---------- ----------
3 2001 6
5 2000 1
7 2001 8
17 2002 8
Dr. Girija Narasimhan
Model Clause
31
Part 10-sql model clause
RETURN UPDATED ROWS
Dr. Girija Narasimhan
Model Clause
32
Suppose in the previous query the entire row those satisfying the condition
location = Sohar and prodno=1. But the output will show newly created row or
inserted row by using rule clause, then use “return updated rows”. Then it will
display only the newly created row.
Dr. Girija Narasimhan
Model Clause
33
Part 11-sql model clause
RETURN All ROWS
By default “return all rows” is used in the model queries Rules clause. Generally if it
is mentioned as return all rows also it will display both updated or non-updated
rows also.
Dr. Girija Narasimhan
Model Clause
35
Part 12-sql model clause
Not use same column in
dimension and measure
Same column for both a dimension and a measure are used in the given below query
i.e "ord" column used in both measure and dimension. Therefore it is giving the error
message.
Dr. Girija Narasimhan
Model Clause
37
Part 13-sql model clause
NULL not allowed in DIMENSION
BY or MEASURES clauses
Null value not allowed in dimension. Because, in general dimension have primary
key column name. So, it doesn't have null values. If null values are allowed then it
is difficult to identify the cell i.e. a reason null value not allowed in the dimension.
So, it is giving error message.
Empty String (' ')
Part 14-sql model clause
Empty string also not allowed in both dimension and measure.
The purpose of the dimension and measure gives multi-
dimensional based result set based on given column values.
Then value is empty, the purpose is not fulfill. So, it is giving
error message of empty string or empty column values.
Using For Loop
Part 15-sql model clause
Using Model clause, looping operation is possible. Using For constructs the single formula
can generate multiple formulas with positional references and it is also used to create new
values.
Using For construct can be used for dimension of numeric, date and date time data types.
Increment and decrement expression can be used in numeric dimensions and interval for
dimensions are used date or date time data types. In the below query dimension has
order id is numeric data type. Here it creates the new value to column Test.
ITERATION
Part 15-sql model clause
For repeating the rules for execution need iterate feature. In this example, sales [19] ||
8 using rules creating new values for sales [19] and assigning value 8. This value will be
execute exactly 5 times given as per condition in iterate (5) in sales [19].
Iteration using until Clause
Part 15-sql model clause
The UNTIL clause is used in the iterate feature for checking at the end of each and every
iteration. It shows iterated rules applied and executed at least once. It also do early
termination based on condition given in the UNTIL clause, because in this below
example iterate (4) times is given. But actually it is doing only one execution of the
iteration because until condition is specified with value 8. So, it do early termination.

Contenu connexe

Tendances

Excel Solver(By Mahsa Rezaei)
Excel Solver(By Mahsa Rezaei)Excel Solver(By Mahsa Rezaei)
Excel Solver(By Mahsa Rezaei)
mahsa rezaei
 
Intro to tsql unit 11
Intro to tsql   unit 11Intro to tsql   unit 11
Intro to tsql unit 11
Syed Asrarali
 

Tendances (20)

What is Outlier Analysis and How Can It Improve Analysis?
What is Outlier Analysis and How Can It Improve Analysis?What is Outlier Analysis and How Can It Improve Analysis?
What is Outlier Analysis and How Can It Improve Analysis?
 
Outlier
OutlierOutlier
Outlier
 
IBM Informix Database SQL Set operators and ANSI Hash Join
IBM Informix Database SQL Set operators and ANSI Hash JoinIBM Informix Database SQL Set operators and ANSI Hash Join
IBM Informix Database SQL Set operators and ANSI Hash Join
 
Common table expressions
Common table expressionsCommon table expressions
Common table expressions
 
Discover the power of Recursive SQL and query transformation with Informix da...
Discover the power of Recursive SQL and query transformation with Informix da...Discover the power of Recursive SQL and query transformation with Informix da...
Discover the power of Recursive SQL and query transformation with Informix da...
 
SQL(database)
SQL(database)SQL(database)
SQL(database)
 
Chapter 6 database normalisation
Chapter 6  database normalisationChapter 6  database normalisation
Chapter 6 database normalisation
 
How mysql choose the execution plan
How mysql choose the execution planHow mysql choose the execution plan
How mysql choose the execution plan
 
The internals
The internalsThe internals
The internals
 
SQL Tunning
SQL TunningSQL Tunning
SQL Tunning
 
3.4 selection sort
3.4 selection sort3.4 selection sort
3.4 selection sort
 
Oracle SQL Advanced
Oracle SQL AdvancedOracle SQL Advanced
Oracle SQL Advanced
 
Visual basic bt0082
Visual basic  bt0082Visual basic  bt0082
Visual basic bt0082
 
Lesson 2.1 array
Lesson 2.1   arrayLesson 2.1   array
Lesson 2.1 array
 
Excel Solver(By Mahsa Rezaei)
Excel Solver(By Mahsa Rezaei)Excel Solver(By Mahsa Rezaei)
Excel Solver(By Mahsa Rezaei)
 
SQL subquery
SQL subquerySQL subquery
SQL subquery
 
Effective Unit Test Style Guide
Effective Unit Test Style GuideEffective Unit Test Style Guide
Effective Unit Test Style Guide
 
MA3696 Lecture 9
MA3696 Lecture 9MA3696 Lecture 9
MA3696 Lecture 9
 
Intro to tsql unit 11
Intro to tsql   unit 11Intro to tsql   unit 11
Intro to tsql unit 11
 
Sql subquery
Sql subquerySql subquery
Sql subquery
 

Similaire à OER UNIT 5 SQL MODEL CLAUSE

MySQL Query And Index Tuning
MySQL Query And Index TuningMySQL Query And Index Tuning
MySQL Query And Index Tuning
Manikanda kumar
 

Similaire à OER UNIT 5 SQL MODEL CLAUSE (20)

VISUAL BASIC 6 - CONTROLS AND DECLARATIONS
VISUAL BASIC 6 - CONTROLS AND DECLARATIONSVISUAL BASIC 6 - CONTROLS AND DECLARATIONS
VISUAL BASIC 6 - CONTROLS AND DECLARATIONS
 
VB_ERROR CONTROL_FILE HANDLING.ppt
VB_ERROR CONTROL_FILE HANDLING.pptVB_ERROR CONTROL_FILE HANDLING.ppt
VB_ERROR CONTROL_FILE HANDLING.ppt
 
MySQL Query And Index Tuning
MySQL Query And Index TuningMySQL Query And Index Tuning
MySQL Query And Index Tuning
 
Part3 Explain the Explain Plan
Part3 Explain the Explain PlanPart3 Explain the Explain Plan
Part3 Explain the Explain Plan
 
ADV Powepoint 3 Lec.pptx
ADV Powepoint 3 Lec.pptxADV Powepoint 3 Lec.pptx
ADV Powepoint 3 Lec.pptx
 
06 procedures
06 procedures06 procedures
06 procedures
 
The Database Environment Chapter 8
The Database Environment Chapter 8The Database Environment Chapter 8
The Database Environment Chapter 8
 
Oracle_Analytical_function.pdf
Oracle_Analytical_function.pdfOracle_Analytical_function.pdf
Oracle_Analytical_function.pdf
 
MS SQL SERVER: Microsoft sequence clustering and association rules
MS SQL SERVER: Microsoft sequence clustering and association rulesMS SQL SERVER: Microsoft sequence clustering and association rules
MS SQL SERVER: Microsoft sequence clustering and association rules
 
MS SQL SERVER: Microsoft sequence clustering and association rules
MS SQL SERVER: Microsoft sequence clustering and association rulesMS SQL SERVER: Microsoft sequence clustering and association rules
MS SQL SERVER: Microsoft sequence clustering and association rules
 
Sql ch 5
Sql ch 5Sql ch 5
Sql ch 5
 
MySQL Performance Optimization
MySQL Performance OptimizationMySQL Performance Optimization
MySQL Performance Optimization
 
Advanced functions in PL SQL
Advanced functions in PL SQLAdvanced functions in PL SQL
Advanced functions in PL SQL
 
Advanced MySQL Query Optimizations
Advanced MySQL Query OptimizationsAdvanced MySQL Query Optimizations
Advanced MySQL Query Optimizations
 
5. Group Functions
5. Group Functions5. Group Functions
5. Group Functions
 
Ground Breakers Romania: Explain the explain_plan
Ground Breakers Romania: Explain the explain_planGround Breakers Romania: Explain the explain_plan
Ground Breakers Romania: Explain the explain_plan
 
C Languages FAQ's
C Languages FAQ'sC Languages FAQ's
C Languages FAQ's
 
MSc COMPUTER APPLICATION
MSc COMPUTER APPLICATIONMSc COMPUTER APPLICATION
MSc COMPUTER APPLICATION
 
Stored procedures
Stored proceduresStored procedures
Stored procedures
 
50 MS Excel Tips and Tricks
50 MS Excel Tips and Tricks 50 MS Excel Tips and Tricks
50 MS Excel Tips and Tricks
 

Plus de Girija Muscut

Plus de Girija Muscut (20)

Tamil Nalvar
Tamil Nalvar Tamil Nalvar
Tamil Nalvar
 
Visualization using Tableau
Visualization using TableauVisualization using Tableau
Visualization using Tableau
 
Introduction to ml
Introduction to mlIntroduction to ml
Introduction to ml
 
Effective Visualization with Tableau
Effective Visualization with TableauEffective Visualization with Tableau
Effective Visualization with Tableau
 
Guruvayoor song with audio-Udayasthamana puja
Guruvayoor song with audio-Udayasthamana puja Guruvayoor song with audio-Udayasthamana puja
Guruvayoor song with audio-Udayasthamana puja
 
Lakshmi lalli with audio
Lakshmi lalli with audioLakshmi lalli with audio
Lakshmi lalli with audio
 
Bagyada laskhmi purandara dasa
Bagyada laskhmi purandara dasaBagyada laskhmi purandara dasa
Bagyada laskhmi purandara dasa
 
Lakshmi lalli
Lakshmi lalliLakshmi lalli
Lakshmi lalli
 
Amba nee irangaayenil - papanasam sivan song
Amba nee irangaayenil - papanasam sivan songAmba nee irangaayenil - papanasam sivan song
Amba nee irangaayenil - papanasam sivan song
 
Mahalakshmi jagan madha - papanasm sivan tamil song
Mahalakshmi jagan madha  - papanasm sivan tamil songMahalakshmi jagan madha  - papanasm sivan tamil song
Mahalakshmi jagan madha - papanasm sivan tamil song
 
Sowbhagayaha laskhmi varuvai nee tamil song
Sowbhagayaha laskhmi varuvai nee tamil songSowbhagayaha laskhmi varuvai nee tamil song
Sowbhagayaha laskhmi varuvai nee tamil song
 
Bega baro Bega baro Neela Megha Varna-Vadhiraja Theertha
Bega baro Bega baro Neela Megha Varna-Vadhiraja TheerthaBega baro Bega baro Neela Megha Varna-Vadhiraja Theertha
Bega baro Bega baro Neela Megha Varna-Vadhiraja Theertha
 
Rama Nama Bhajan
Rama Nama BhajanRama Nama Bhajan
Rama Nama Bhajan
 
Saratha devi song 1
Saratha devi song 1Saratha devi song 1
Saratha devi song 1
 
Saraswathi bhajan 1 with tamil meaning
Saraswathi bhajan 1 with tamil meaningSaraswathi bhajan 1 with tamil meaning
Saraswathi bhajan 1 with tamil meaning
 
Aneyu karadare -Purandara Dasar.
Aneyu karadare -Purandara Dasar.Aneyu karadare -Purandara Dasar.
Aneyu karadare -Purandara Dasar.
 
Maithriam Bhajatha with tamil meaning (lyrics)
Maithriam Bhajatha with tamil meaning (lyrics)Maithriam Bhajatha with tamil meaning (lyrics)
Maithriam Bhajatha with tamil meaning (lyrics)
 
Unit 4 scd2-exercise 1-solution
Unit 4 scd2-exercise 1-solutionUnit 4 scd2-exercise 1-solution
Unit 4 scd2-exercise 1-solution
 
Unit 2 - Slowly Changing Dimension Type 1 (SCD1) (insert)
Unit 2  - Slowly Changing Dimension Type 1 (SCD1) (insert)Unit 2  - Slowly Changing Dimension Type 1 (SCD1) (insert)
Unit 2 - Slowly Changing Dimension Type 1 (SCD1) (insert)
 
Slowly Changing Dimension Type 1 (SCD 1) exercise 2 solution insert and update
Slowly Changing Dimension Type 1 (SCD 1) exercise 2 solution insert and updateSlowly Changing Dimension Type 1 (SCD 1) exercise 2 solution insert and update
Slowly Changing Dimension Type 1 (SCD 1) exercise 2 solution insert and update
 

Dernier

Mastering Windows 7 A Comprehensive Guide for Power Users .pdf
Mastering Windows 7 A Comprehensive Guide for Power Users .pdfMastering Windows 7 A Comprehensive Guide for Power Users .pdf
Mastering Windows 7 A Comprehensive Guide for Power Users .pdf
mbmh111980
 
AI/ML Infra Meetup | Improve Speed and GPU Utilization for Model Training & S...
AI/ML Infra Meetup | Improve Speed and GPU Utilization for Model Training & S...AI/ML Infra Meetup | Improve Speed and GPU Utilization for Model Training & S...
AI/ML Infra Meetup | Improve Speed and GPU Utilization for Model Training & S...
Alluxio, Inc.
 

Dernier (20)

CompTIA Security+ (Study Notes) for cs.pdf
CompTIA Security+ (Study Notes) for cs.pdfCompTIA Security+ (Study Notes) for cs.pdf
CompTIA Security+ (Study Notes) for cs.pdf
 
SQL Injection Introduction and Prevention
SQL Injection Introduction and PreventionSQL Injection Introduction and Prevention
SQL Injection Introduction and Prevention
 
OpenChain @ LF Japan Executive Briefing - May 2024
OpenChain @ LF Japan Executive Briefing - May 2024OpenChain @ LF Japan Executive Briefing - May 2024
OpenChain @ LF Japan Executive Briefing - May 2024
 
INGKA DIGITAL: Linked Metadata by Design
INGKA DIGITAL: Linked Metadata by DesignINGKA DIGITAL: Linked Metadata by Design
INGKA DIGITAL: Linked Metadata by Design
 
Automate your OpenSIPS config tests - OpenSIPS Summit 2024
Automate your OpenSIPS config tests - OpenSIPS Summit 2024Automate your OpenSIPS config tests - OpenSIPS Summit 2024
Automate your OpenSIPS config tests - OpenSIPS Summit 2024
 
Top Mobile App Development Companies 2024
Top Mobile App Development Companies 2024Top Mobile App Development Companies 2024
Top Mobile App Development Companies 2024
 
5 Reasons Driving Warehouse Management Systems Demand
5 Reasons Driving Warehouse Management Systems Demand5 Reasons Driving Warehouse Management Systems Demand
5 Reasons Driving Warehouse Management Systems Demand
 
Microsoft365_Dev_Security_2024_05_16.pdf
Microsoft365_Dev_Security_2024_05_16.pdfMicrosoft365_Dev_Security_2024_05_16.pdf
Microsoft365_Dev_Security_2024_05_16.pdf
 
Mastering Windows 7 A Comprehensive Guide for Power Users .pdf
Mastering Windows 7 A Comprehensive Guide for Power Users .pdfMastering Windows 7 A Comprehensive Guide for Power Users .pdf
Mastering Windows 7 A Comprehensive Guide for Power Users .pdf
 
Entropy, Software Quality, and Innovation (presented at Princeton Plasma Phys...
Entropy, Software Quality, and Innovation (presented at Princeton Plasma Phys...Entropy, Software Quality, and Innovation (presented at Princeton Plasma Phys...
Entropy, Software Quality, and Innovation (presented at Princeton Plasma Phys...
 
OpenChain Webinar: AboutCode and Beyond - End-to-End SCA
OpenChain Webinar: AboutCode and Beyond - End-to-End SCAOpenChain Webinar: AboutCode and Beyond - End-to-End SCA
OpenChain Webinar: AboutCode and Beyond - End-to-End SCA
 
Facemoji Keyboard released its 2023 State of Emoji report, outlining the most...
Facemoji Keyboard released its 2023 State of Emoji report, outlining the most...Facemoji Keyboard released its 2023 State of Emoji report, outlining the most...
Facemoji Keyboard released its 2023 State of Emoji report, outlining the most...
 
Lessons Learned from Building a Serverless Notifications System.pdf
Lessons Learned from Building a Serverless Notifications System.pdfLessons Learned from Building a Serverless Notifications System.pdf
Lessons Learned from Building a Serverless Notifications System.pdf
 
Workforce Efficiency with Employee Time Tracking Software.pdf
Workforce Efficiency with Employee Time Tracking Software.pdfWorkforce Efficiency with Employee Time Tracking Software.pdf
Workforce Efficiency with Employee Time Tracking Software.pdf
 
AI/ML Infra Meetup | Improve Speed and GPU Utilization for Model Training & S...
AI/ML Infra Meetup | Improve Speed and GPU Utilization for Model Training & S...AI/ML Infra Meetup | Improve Speed and GPU Utilization for Model Training & S...
AI/ML Infra Meetup | Improve Speed and GPU Utilization for Model Training & S...
 
How to install and activate eGrabber JobGrabber
How to install and activate eGrabber JobGrabberHow to install and activate eGrabber JobGrabber
How to install and activate eGrabber JobGrabber
 
Naer Toolbar Redesign - Usability Research Synthesis
Naer Toolbar Redesign - Usability Research SynthesisNaer Toolbar Redesign - Usability Research Synthesis
Naer Toolbar Redesign - Usability Research Synthesis
 
AI/ML Infra Meetup | Reducing Prefill for LLM Serving in RAG
AI/ML Infra Meetup | Reducing Prefill for LLM Serving in RAGAI/ML Infra Meetup | Reducing Prefill for LLM Serving in RAG
AI/ML Infra Meetup | Reducing Prefill for LLM Serving in RAG
 
COMPUTER AND ITS COMPONENTS PPT.by naitik sharma Class 9th A mittal internati...
COMPUTER AND ITS COMPONENTS PPT.by naitik sharma Class 9th A mittal internati...COMPUTER AND ITS COMPONENTS PPT.by naitik sharma Class 9th A mittal internati...
COMPUTER AND ITS COMPONENTS PPT.by naitik sharma Class 9th A mittal internati...
 
IT Software Development Resume, Vaibhav jha 2024
IT Software Development Resume, Vaibhav jha 2024IT Software Development Resume, Vaibhav jha 2024
IT Software Development Resume, Vaibhav jha 2024
 

OER UNIT 5 SQL MODEL CLAUSE

  • 1. Data warehouse Design Using Oracle https://www.oercommons.org/authorin g/edit/21861 Dr. Girija Narasimhan 1 OER- UNIT 5 SQL MODEL CLAUSE
  • 2. Part 1- SQL model clause 2 Dr. Girija Narasimhan Model Clause
  • 3. 3 Dr. Girija Narasimhan Model Clause With the SQL model clause you build one or more matrixes with a variable number of dimensions. This is called the model. The model uses a subset of the available columns from your FROM clause. It contains at least one dimension, at least one measure and optionally one or more partitions create table salesorder(ord number(4) primary key,prodno number(3),suppno number(3),time number(5),location varchar2(20),sales number(6));
  • 4. 4 Dr. Girija Narasimhan Model Clause Ord Prodno Suppno Time Location sales 1 1 1 2000 Sohar 5 2 1 1 2000 Muscat 3 3 1 1 2001 Sohar 6 4 1 1 2001 Muscat 4 5 1 2 2000 Sohar 1 6 1 2 2000 Muscat 7 7 1 2 2001 Sohar 8 8 1 2 2001 Musat 5 9 2 1 2000 Sohar 3 10 2 1 2000 Muscat 8 11 2 1 2001 Sohar 6 12 2 1 2001 Muscat 7 13 2 2 2000 Sohar 9 14 2 2 2000 Muscat 11 15 2 2 2001 Sohar 4 16 2 2 2001 Muscat 3
  • 5. 5 Dr. Girija Narasimhan Model Clause Partition columns Partition columns divide the result set into blocks. Rules defined in the model clause are applied independently of other partitions to each partition. Dimension columns Dimension columns define how cells within a partition can be accessed. Measure columns The columns defined as measures can be assigned new values in the rules section of the model clause.
  • 6. 6 Dr. Girija Narasimhan Model Clause Part 2- Dimension by Unique column
  • 7. Dr. Girija Narasimhan Model Clause 7 Dimension by Unique column Multi dimension column Aliasing Expression
  • 8. Dr. Girija Narasimhan Model Clause 8 In the model clause, the dimension components are used to define multi-dimension array and it is also useful for identifying cells or column within the partition. By default it will identify at least one cell in a partition The dimension components have the column name which has unique value
  • 9. Dr. Girija Narasimhan Model Clause 9 Query Output Select ord, sales from salesorder Where time=2000 model dimension by(ord) measures(sales) rules() order by ord; ORD SALES ---------- ---------- 1 5 2 3 5 1 6 7 9 3 10 8 13 9 14 11 8 rows selected.
  • 10. Dr. Girija Narasimhan Model Clause 10 Column value given in the dimension is not unique then it will give "non unique addressing" error.
  • 11. Dr. Girija Narasimhan Model Clause 11 Part 3- Dimension by Multiple dimension using unique keys
  • 12. Dr. Girija Narasimhan Model Clause 12 It is possible to use more than one dimension column be specified. But all the combination gives the unique row identification
  • 13. Dr. Girija Narasimhan Model Clause 13 Part 4- Dimension by aliasing
  • 14. Dr. Girija Narasimhan Model Clause 14 In the result set, the user desired column name can be displayed by using aliasing "as" in the dimension.
  • 15. Dr. Girija Narasimhan Model Clause 15 Part 5- Dimension by Expression
  • 16. Dr. Girija Narasimhan Model Clause 16 It is possible to use expression in the dimension component. In the given query, value of the ord column is multiplied by 10. So, column value 3 is displaying as 30.
  • 17. Dr. Girija Narasimhan Model Clause 17 Part 6-sql model clause Measures
  • 18. Dr. Girija Narasimhan Model Clause 18 Measure is a data column of the table. It is similar to measure in the star schema based fact table. Generally measures have numeric based values like cost or amount. Each cell or column mentioned in the measures is accessed by specifying its full combination of dimensions.
  • 20. Dr. Girija Narasimhan Model Clause 20 Like dimension it is possible to write expression in the measure column also.
  • 21. Dr. Girija Narasimhan Model Clause 21 Part 7-sql model clause Partition by
  • 22. Dr. Girija Narasimhan Model Clause 22 The Oracle data warehousing describes partition as a logical block of the result set. It is similar to how partition in the analytical functions. Each partition is viewed by the formula mentioned in the partition by component and treated as an independent array.
  • 24. Dr. Girija Narasimhan Model Clause 24 Part 8-sql model clause Rules
  • 25. Dr. Girija Narasimhan Model Clause 25 In the model clause, rules hold the expressions that assign values to measures. A rule is an assignment statement whose left side represents a cell or a range of cells and whose right side is an expression involving constants, bind variables or individual cell or aggregate function. There are three terms used in rules namely cell reference, dimension reference, cell assignment.
  • 27. Dr. Girija Narasimhan Model Clause 27 The term "newsal" is called a "cell reference, Cell references (i.e newsal) can only refer to measure cells, not dimension cells. The dimension reference is part between the square bracket [] in the cell reference When a cell reference is used as the assignment target on the left side of a rule equation is called cell assignment. newsal[1]=100 Cell reference ,it refers measures Dimension reference Cell Assignment
  • 28. Dr. Girija Narasimhan Model Clause 28 Part 9-sql model clause Rules create new row
  • 29. Dr. Girija Narasimhan Model Clause 29 The RULES clause also used to create new rows in the result set
  • 30. Dr. Girija Narasimhan Model Clause 30 Adding values to newly created row It is also possible to add values to newly created row by using Rules Clause Query Result Select ord,time,sales from salesorder Where location=’Sohar’ and prodno=1 Model dimension by(ord) Measures(time,sales) Rules(time[17]=2002,sales[17]=8); ORD TIME SALES ---------- ---------- ---------- 3 2001 6 5 2000 1 7 2001 8 17 2002 8
  • 31. Dr. Girija Narasimhan Model Clause 31 Part 10-sql model clause RETURN UPDATED ROWS
  • 32. Dr. Girija Narasimhan Model Clause 32 Suppose in the previous query the entire row those satisfying the condition location = Sohar and prodno=1. But the output will show newly created row or inserted row by using rule clause, then use “return updated rows”. Then it will display only the newly created row.
  • 33. Dr. Girija Narasimhan Model Clause 33 Part 11-sql model clause RETURN All ROWS
  • 34. By default “return all rows” is used in the model queries Rules clause. Generally if it is mentioned as return all rows also it will display both updated or non-updated rows also.
  • 35. Dr. Girija Narasimhan Model Clause 35 Part 12-sql model clause Not use same column in dimension and measure
  • 36. Same column for both a dimension and a measure are used in the given below query i.e "ord" column used in both measure and dimension. Therefore it is giving the error message.
  • 37. Dr. Girija Narasimhan Model Clause 37 Part 13-sql model clause NULL not allowed in DIMENSION BY or MEASURES clauses
  • 38. Null value not allowed in dimension. Because, in general dimension have primary key column name. So, it doesn't have null values. If null values are allowed then it is difficult to identify the cell i.e. a reason null value not allowed in the dimension. So, it is giving error message.
  • 39. Empty String (' ') Part 14-sql model clause
  • 40. Empty string also not allowed in both dimension and measure. The purpose of the dimension and measure gives multi- dimensional based result set based on given column values. Then value is empty, the purpose is not fulfill. So, it is giving error message of empty string or empty column values.
  • 41. Using For Loop Part 15-sql model clause
  • 42. Using Model clause, looping operation is possible. Using For constructs the single formula can generate multiple formulas with positional references and it is also used to create new values. Using For construct can be used for dimension of numeric, date and date time data types. Increment and decrement expression can be used in numeric dimensions and interval for dimensions are used date or date time data types. In the below query dimension has order id is numeric data type. Here it creates the new value to column Test.
  • 43.
  • 45. For repeating the rules for execution need iterate feature. In this example, sales [19] || 8 using rules creating new values for sales [19] and assigning value 8. This value will be execute exactly 5 times given as per condition in iterate (5) in sales [19].
  • 46. Iteration using until Clause Part 15-sql model clause
  • 47. The UNTIL clause is used in the iterate feature for checking at the end of each and every iteration. It shows iterated rules applied and executed at least once. It also do early termination based on condition given in the UNTIL clause, because in this below example iterate (4) times is given. But actually it is doing only one execution of the iteration because until condition is specified with value 8. So, it do early termination.