Call now: 252-767-6166  
Oracle Training Oracle Support Development Oracle Apps

 E-mail Us
 Oracle Articles
New Oracle Articles

 Oracle Training
 Oracle Tips

 Oracle Forum
 Class Catalog

 Remote DBA
 Oracle Tuning
 Emergency 911
 RAC Support
 Apps Support
 Oracle Support

 SQL Tuning

 Oracle UNIX
 Oracle Linux
 Remote s
 Remote plans
 Application Server

 Oracle Forms
 Oracle Portal
 App Upgrades
 SQL Server
 Oracle Concepts
 Software Support

 Remote S


 Consulting Staff
 Consulting Prices
 Help Wanted!


 Oracle Posters
 Oracle Books

 Oracle Scripts

Don Burleson Blog 









Using The SQL MODEL Clause To Generate Financial Statements

Oracle tips by Burleson


By Mark Rittman, June 2005

Also see these notes on the SQL model clause.

So what we're looking for the MODEL clause to do is to fill in the actual and budget figures for each of the departments, create additional rows to hold totals and averages for the organisation as a whole, then fill in the variances.

The first step then is to write the base SELECT statement for the query:

create or replace view financial_statement_model as
select rep_line_id, rep_line_item, department, actual, budget, variance
from   financial_statement

Now, we add in the first part of the MODEL clause, that defines the dimensions and measures.

dimension by (rep_line_id, department)
measures     (rep_line_item, actual, budget, variance)
The dimensions are the line number for the line item (net sales, other income, wages % of sales) and the departments for which were are going to produce the reports. The measures are the items in the MODEL that we are going to either reference or calculate. You may well at this point be noticing the similarity between an SQL MODEL and an analytic workspace - both have dimensions, both have measures - as what Oracle is going to do when we kick the MODEL clause off is to create a temporary analytic workspace in the background, load our data in, then use the MODEL facility within the OLAP engine to perform our calculations. Quite cool actually and it doesn't require you to have licensed the OLAP Option to use it.

(UPDATE 1/7/05: It looks like, although you don't need to license the OLAP Option to use this feature, you need to have it installed. I can't find any reference to the OLAP Option in the context of the MODEL clause within the online docs, and no note that you need to have licensed it to use the MODEL clause, but a reader wrote in last night and let me know that the examples don't work without the OLAP Option installed. To confirm licensing, the best bet is to check with your local Oracle rep.)

What happens now is that the MODEL clause in the background creates three variables (measures), each dimensioned by rep_line_item and department, which we can then manipulate via our MODEL. The next bit is where we start to add the rules for the model.

rules upsert
actual [4,department] = actual[2,cv(department)] + actual [3,cv(department)],
budget [4,department] = budget[2,cv(department)] + budget [3,cv(department)],

Note the RULES UPSERT bit - the RULES part tells the MODEL clause that this is where the rules come in, and the UPSERT bit allows the model to create additional cells in the model - referred to as custom dimension members - which we'll need so that we can store additional entries for the figures for the company as a whole.

The first rules of the model tell Oracle to calculate the figure for line item 4 (total net income) from the sum of lines 2 and 3. Note that we reference actual [4,department] - we need to specify both dimension values to get to our actuals figure, and the "department" bit tells the model to calculate figures for all members for this dimension - we could reference just one department dimension member rather than all of them by specifying actual [4,'Retail'] instead.

The cv(department) bit tells the model to use the "current value" of the dimension as specified on the left hand side of the equation; therefore, when the model is calculating the total net income for "Retail", it uses the gross profit and actual income for "Retail" as the calculation inputs.

actual [8,department] = sum(actual)[rep_line_id between 5 and 7, cv(department)],
budget [8,department] = sum(budget)[rep_line_id between 5 and 7, cv(department)],

The next two lines, rather than individually specifying other line item dimension members for addition, specify a range of dimension members instead.

actual [9,department] = actual[4,cv(department)] - actual [8,cv(department)],
budget [9,department] = budget[4,cv(department)] - budget [8,cv(department)],

These next two lines are the same as our first two lines, but this time subtract line 8 (total costs) from total net income (line 4).



Oracle Training at Sea
oracle dba poster

Follow us on Twitter 
Oracle performance tuning software 
Oracle Linux poster


Burleson is the American Team

Note: This Oracle documentation was created as a support and Oracle training reference for use by our DBA performance tuning consulting professionals.  Feel free to ask questions on our Oracle forum.

Verify experience! Anyone considering using the services of an Oracle support expert should independently investigate their credentials and experience, and not rely on advertisements and self-proclaimed expertise. All legitimate Oracle experts publish their Oracle qualifications.

Errata?  Oracle technology is changing and we strive to update our BC Oracle support information.  If you find an error or have a suggestion for improving our content, we would appreciate your feedback.  Just  e-mail:  and include the URL for the page.


Burleson Consulting

The Oracle of Database Support

Oracle Performance Tuning

Remote DBA Services


Copyright © 1996 -  2016

All rights reserved by Burleson

Oracle ® is the registered trademark of Oracle Corporation.