当前位置: 代码迷 >> SQL >> 《Pro Oracle SQL》CHAPTER 九 The Model Clause - 9.1 Spreadsheets
  详细解决方案

《Pro Oracle SQL》CHAPTER 九 The Model Clause - 9.1 Spreadsheets

热度:79   发布时间:2016-05-05 15:09:46.0
《Pro Oracle SQL》CHAPTER 9 The Model Clause -- 9.1 Spreadsheets

The Model Clause??? Model子句?? (page 273)

Riyaj Shamsudeen
??? The Model clause introduced in the Oracle Database version 10g provides an elegant method to
replace the spreadsheet. With the Model clause, it is possible to utilize powerful features such as
aggregation, parallelism, and multi-dimensional, multi-variate analysis in? SQL statements. If you
enjoy working with Excel spreadsheets to calculate formulas, you will enjoy working with the Model
clause, too. ?
??? Model子句在Oracle数据库10版本引入,提供了一种优雅的方式替代电子数据表(的计算)。使用Model子句,就有可能利用其强大的特性,在SQL语句中实现诸如聚合,平行和多维度,多变量的分析。如果你喜欢使用Excel电子表格计算公式,你也就会喜欢使用Model子句。
??? In situations where the amount of data to be processed is small, the inter-row referencing and
calculating power of the spreadsheet is sufficient to accomplish
the task at hand. However, scalability
of such a spreadsheet as a data warehouse application is limited and cumbersome.
For example,
spreadsheets are generally limited to two or three dimensions, and creating spreadsheets with more
dimensions is a manually intensive task. Also, as the amount of data increases, the execution of
formulas slows down in a spreadsheet. Furthermore, there is an upper limit on the number of rows in a
spreadsheet workbook.
??? 对于处理的是少量数据的情况,行间引用和电子表格的计算能力足以应付手头的任务。然而,若是数据仓库应用的电子数据表的可扩展性将是受限的和累赘的例如,电子数据表一般限定为二维或者三维,创建更多维的电子数据表是一项手工繁重的任务。而且,随着数据量的增加,电子数据表中的公式的执行会变慢。再者,在电子表格的工作薄中行数是有上限的。
??? Since the Model clause is an extension to the SQL language application. the Model clause is highly
scalable, akin to the Oracle database’s scalability. Multi-dimensional, multi-variate calculations over
millions of rows, if not billions of rows, can be implemented easily with the Model clause, unlike with
spreadsheets. Also, many database features such as object partitioning and parallel execution can be
used effectively with the Model clause, thereby further improving scalability. ?
??? 因为Mode子句是Sql语言应用的延伸,Model子句具有的高度可扩展能力类似于Oracle的扩展能力。在上百万行数行上,只要不是上十亿行,多维度,多变量计算可用Model子句轻易的执行,不像电子表格。还有,许多数据库特性如对象分区和平行执行都能高效的使用Model子句,因而进一步提高可扩展性。
??? Aggregation of the data is performed inside the RDBMS engine, avoiding costly round-trip calls as
in the case of the third party datawarehouse tools. Scalability is further enhanced by out-of-the-box
parallel processing capabilities and query rewrite facilities.
??? 数据的聚合是在RDBMS引擎中执行的,避免了高成本的往返调用第三方数据仓库工具。通过现成的并行处理功能和查询重写工具,可扩展性进一步增强。

??? The key difference between conventional SQL statement and the Model clause is that the Model
clause supports inter-row references, multi-cell references, and cell aggregation.
It is easier to
understand the Model clause with examples, so I will introduce the Model clause with examples. Then
I’ll discuss the advanced features in the Model clause. ?
?? 传统SQL语句和Model子句的关键不同在于Model子句支持行间引用,多单元格引用,和单元格聚合。通过例子更容易理解Model子句,因此我将通过例子介绍Model子句。接下来再讨论Model子句的高级特性。


9.1 Spreadsheets???? 电子数据表(电子表格)

??? Let’s consider the spreadsheet in Listing 9-1. In this spreadsheet, the inventory for a region and week
is calculated using a formula: current inventory is the sum of last week’s inventory and the quantity
received in this week minus the quantity sold in this week. This formula is shown in the example using
Excel spreadsheet notation. For example, the formula for week 2’s inventory would be? =B5+C4-C3 ,
where B5 is the prior week’s inventory, C4 is the current week’s receipt_qty and C3 is the current
week’s sales_qty. Essentially, this formula uses an inter-row reference to calculate the inventory.
??? 我们看一下列表9-1的电子表格。在这个电子表格中,区域和星期的库存通过公式计算:当前的库存是上一周的库存与本周接收的数量之和再减去本周售出的数量。例子中的公式使用了Excel电子表格记法。例如,第二周的库存公式是=B5+C4-C3 ,其中B5是上一周的库存,C4是当前周接收量,C3是当前周的销售量。实质上,该公式使用了行间引用来计算库存。

Listing 9-1.? Spreadsheet Formula to Calculate Inventory??? 电子表格公式计算库存
Product = Xtend Memory, Country =’Australia’

?

ABCDEFG
Year=2001Week->





123456
Sale92.26 118.38 47.24 256.70 93.44 43.17
Receipts96.89 149.17 49.60 259.10 98.66 20.22
Inventory4.63 35.42 37.78 40.18 45.41 22.44


=B5+C4-C3



?

??? While it’s easy to calculate this formula for a few dimensions using a spreadsheet, it’s much more
difficult to perform these calculations with more dimensions. Performance suffers as the amount of
data increases in the spreadsheet. These issues can be remedied by using the Model clause that the
Oracle Database provides. Not only does the Model clause provide for efficient formula calculations,
but the writing of multi-dimensional, multi-variate analysis also becomes much more practical.?

??? 虽然对低纬度的(数据)使用电子表格计算该公式比较容易,但是执行多维度的计算会非常困难。随着电子表格中的数据量的增大使得性能受到影响。这个问题可以通过使用Oracle数据库提供的Model子句弥补。Model子句不但提供高效的公式计算,而且使得书写多维度,多变量分析变得更加的实际。

  相关解决方案