Lookup Tables???? 查找表(page 290)
??? You can define a lookup table and refer to that lookup table in the rules section. Such a lookup table is
sometimes termed a? reference table . Reference tables are defined in the initial section of the SQL
statement and then referred in the rules section of the SQL statement.
??? 你可以定义一查找表且在规则段引用该查找表。该查找表有时被称之为引用表。引用表在SQL语句的初始化段定义而在SQL语句的规格段引用。
??? In Listing 9-19, lines 5 to 9 define a lookup table ref_prod? using a Reference? clause. Line 5
REFERENCE ref_prod is specifying ref_prod as a lookup table. Column Prod_name is a dimension
column as specified in line 8 and column Prod_list_price is a measures column. Note that the
reference table must be unique on dimension column and should retrieve exactly one row per
dimension column’s value.?
??? 在列表9-19,5到9行使用Reference子句定义lookup表ref_prod。行5 REFERENCE ref_prod定义ref_prod为一查找表。在第8行定义列Prod_name是维度列且列Prod_list_price是度量列。注意引用表必须是在维度列上唯一且每一维度列值应当准确的检索一行。
??? Line 10 specifies the main model section starting with the keyword MAIN. This section is named as
main_section for ease of understanding, although any name can be used. In the line 15, a rule for the
column Prod_list_price is specified and populated from the lookup table ref_prod. Line 16 shows that
the reference table that measures columns is accessed using the clause? ref_prod.prod_list_price
[cv(product)] . The current value of the Product column is passed as a lookup key in the lookup table
using the clause? cv(product) .
??? 行10定义主model段由关键字MAIN开头。虽然可以使用任意命名,但为容易理解该段命名为main_section。在15行指定了对列Prod_list的规则且由来自查找表ref_prod。行16展示度量列访问了查找表,使用子句ref_prod.prod_list_price[cv(product)]。Product列的当前值作为查找表中的查找键传入,使用子句cv(product)。
??? In summary, you define a lookup table using a? REFERENCE clause, and then access that lookup table
using the syntax? look_table_name.measures column . For example, the syntax in this example is
ref_prod.prod_list_price [cv(product)]. To access a specific row in the lookup table, you pass the
current value of the dimension column from the left hand side of the rule, in this example, using the
cv(product) clause. You might be able to understand better if you imagine ref_prod as a table,
cv(product)? as primary key in to that table, and prod_list_price as a column to fetch from that lookup
table.
??? 总结一下,你用REFERENCE 子句定义一个查找表,而用句法“查找表名.度量列”访问查找表。例如,在本例中的句法是ref_prod.prod_list_price [cv(product)]。为了访问查找表中的特定行,你规则的左手边传入维度列的当前值,在本例中,用cv(product) 子句。如果你想象ref_prod 是一张表可能能更好的理解,cv(product) 作为那个表的主键,而prod_list_price 作为一列取自查找表。
Listing 9-19.? Reference Model
?1???? select year, week,sale, prod_list_price
?2??????? from sales_fact
?3??????? where country in ('Australia') and product ='Xtend Memory'
?4??????? model return updated rows
?5??????? REFERENCE ref_prod on
?6????????? (select prod_name, max(prod_list_price) prod_list_price from products
?7???????????? group by prod_name)
?8?????????? dimension by (prod_name)
?9?????????? measures (prod_list_price)
10??????? MAIN main_section
11????????? partition by (product, country)
12????????? dimension by (year, week)
13????????? measures ( sale, receipts, 0 prod_list_price )
14????????? rules?? (
15????????????? prod_list_price[year,week] order by year, week =
16????????????????????????????????? ref_prod.prod_list_price [ cv(product) ]
17??????? )
18*?? order by year, week;
?
?YEAR WEEK?????? SALE PROD_LIST_PRICE
----- ---- ---------- ---------------
?2000?? 31????? 44.78?????????? 20.99
?2000?? 33???? 134.11?????????? 20.99
?2000?? 34???? 178.52?????????? 20.99
...
?
??? More lookup tables can be added if needed. Suppose you also need to retrieve the
country_iso_code column values from another table. You achieved that by adding a lookup table
ref_country?? as shown in Listing 9-20 lines 10 to 13. Column Country_name is the dimension column
and Country_iso_code is a measures column. Lines 22 and 23 refer to the lookup table using a new
rule Iso_code.? This rule is accessing the lookup table ref_country using the Current Value of the
Country column as the lookup key.?
??? 如果需要可以加入多个查找表。假设你也需要从其它表检索country_iso_code列值。你可以加入另一个查找表ref_country达到目的,如列表9-20的行10到13所示。列Country_name是维度列而Country_iso_code是度量列。行22和23用新规则Iso_code引用lookup表。这个规则访问查找表ref_country,使用Country列的当前值作为查找键。
Listing 9-20.? More Lookup Tables
?1???? select year, week,sale,? prod_list_price, iso_code
?2??????? from sales_fact
?3??????? where country in ('Australia') and product ='Xtend Memory'
?4??????? model return updated rows
?5??????? REFERENCE ref_prod on
?6????????? (select prod_name, max(prod_list_price) prod_list_price from
?7???????????? products group by prod_name)
?8?????????? dimension by (prod_name)
?9?????????? measures (prod_list_price)
10??????? REFERENCE ref_country on
11????????? (select country_name, country_iso_code from countries)
12?????????? dimension by (country_name )
13?????????? measures (country_iso_code)
14??????? MAIN main_section
15????????? partition by (product, country)
16????????? dimension by (year, week)
17????????? measures (? sale, receipts, 0 prod_list_price ,
18????????????????????????????? cast(' ' as varchar2(5)) iso_code)
19????????? rules?? (
20????????????? prod_list_price[year,week] order by year, week =
21???????????????????????????? ref_prod.prod_list_price [ cv(product) ],
22????????????? iso_code [year, week] order by year, week =
23???????????????????????????? ref_country.country_iso_code [ cv(country)]
24??????? )
25*?? order by year, week
?
YEAR WEEK?????? SALE??????? PROD_LIST_PRICE???? ISO_C
----?? ---- ?? ---------- ? ? ---------------?????? -----
2000?? 31????? 44.78?????????? 20.99???????????????????? AU
2000?? 33???? 134.11?????????? 20.99??????????????????? AU
2000?? 34???? 178.52?????????? 20.99??????????????????? AU
2000?? 35????? 78.82?????????? 20.99???????????????????? AU
2000?? 36???? 118.41?????????? 20.99???????????????????? AU
?...
详细解决方案
《Pro Oracle SQL》CHAPTER 九 The Model Clause - 9.8 Lookup Tables
热度:301 发布时间:2016-05-05 15:10:48.0
相关解决方案
- oracle 分页排序,ssi,该怎么处理
- oracle 最近的时间(而不是前一天的时间) 跪求sql语句 。解决方法
- oracle,该怎么解决
- 在 Hibernate3 查询不到 Oracle 11g 里的记录
- oracle 安装时出现 java tm 异常
- android访问其他数据库(如:oracle、MySql等),希望大家给点建议!解决方案
- oracle 安插 LONG VARCHAR 类型数据
- ORACLE 一条SQL的有关问题
- oracle loadjava如何用
- javaBean 跟 Model 的关系
- oracle,该如何处理
- C# + SQL server +oracle QQ交流群142703980解决方法
- 哪位高手能帮忙告诉小弟我borland 2006/2007 的 model view 设计的资料
- 怎么跟踪winform应用程序发送到数据库的sql(oracle、mssql)
- js里头拼字符串 @Model.VirDir + "views[*0].swf," + @Model.FlvCount + "}"
- @foreach (var doc in Model.Magazine),该如何解决
- @Model.CurrentArticle.PubDate.ToString("yyyy-MM-dd HH:mm")解决方案
- @model IEnumerable<MvcMovie.Models.Movie>该怎么解决
- , 每次玩ASP都会遇到一些恶心的有关问题, 这次是:未能加载文件或程序集“Oracle.DataAccess”或它的某一个依赖项
- DataSet.Tables 中怎么插入值
- 尝试加载 Oracle 客户端库时引发 BadImageFormatException。如果在安装 32 位 Oracle 客户端组件的情况下以 64 位模式运,该怎么解决
- 求解:gridview行值的计算并绑定有关问题(asp.net+oracle)
- Oracle.DataAccess 执行多条sql语句,该如何解决
- ds.Tables[0].Rows.Count 能查到0表 但count=0 sql语句没有关问题
- asp.net mvc 中 Html.EditorFor 怎么添加 htmlattribute 属性 小弟我想把 @Html.EditorFor(model
- VS10连接Oracle的有关问题:"Oracle.DataAccess.Client.OracleConnection"的类型初始值设定项引发错误
- System.Data.OleDb.OleDbException: 未找到 Oracle 客户端和网络组件。
- asp.net oracle 参数化 模糊查询出错,该怎么处理
- 关于Ilist<Model> 取值,该如何处理
- 无法将类型“Maticsoft.Model.Login”隐式转换为“WebAppDL.admin.Login,该如何解决