我的家园

我的家园

Returning Updated Rows   返回更新的行       (page 280)
    In Listing 9-7, just four rows were returned even though there are rows for other weeks. The clause
RETURN UPDATED ROWS  controls this behavior and provides the ability to limit the cells returned by the
SQL statement. Without this clause, all rows are returned regardless of whether the rules updates the
cells or not.
The rule in Listing 9-7 updates only four cells and other cells are untouched, and so just
four rows are returned. 
    在列表9-7中,只返回了四行,尽管有其它week的行。子句RETURN UPDATED ROWS控制该行为且为SQL语句提供限制返回单元格的能力。没有这个子句,将返回所有行,不论规则是否更新了单元格。 在列表9-7的规则只更新了四行而其它的单元格没有触及,因此只返回了四行。
    What happens if you don’t specify the clause return updated rows ? Listing 9-9 shows the output
without the  return updated rows  clause. The output in this listing shows that both updated and non-
updated rows are returned from the SQL statement. The rule updates cells for the weeks 1, 52, and 53
only, but the output rows in Listing 9-9 shows rows with other column values such as 2, 3, 4, too.
    如果你没有指定子句 return updated rows 会怎样?列表9-9展示了没有 return updated rows 子句的输出。这个列表的输出显示从SQL语句中更新和没有更新的行都返回了。规则只更新单元格weeks 1,52和53,但是列表9-9的输出显示其它的列值如2,3,4的行也输出了。
Listing 9-9.  SQL without RETURN UPDATED ROWS
  1    select product, country, year, week, sale
  2    from sales_fact
  3    where country in ('Australia') and product ='Xtend Memory'
  4    model 
  5    partition by (product, country)
  6    dimension by (year, week)
  7    measures ( sale)
  8    rules(
  9           sale [ year in (2000,2001), week in (1,52,53) ] order by year, week
 10                    = sale [cv(year), cv(week)] * 1.10
 11    )
 12*   order by product, country,year, week
PRODUCT      COUNTRY     YEAR  WEEK       SALE
------------        ----------          -----      ----          ----------
...
Xtend Memory Australia       2000       50          21.19
Xtend Memory Australia       2000       52          74.20
Xtend Memory Australia       2001        1          101.49
Xtend Memory Australia       2001        2          118.38
Xtend Memory Australia       2001        3           47.24
Xtend Memory Australia       2001        4          256.70
...
    The clause RETURN UPDATED ROWS  is applicable to statements using positional notation also. In the
Listing 9-10, a rule using a positional notation is shown, inserting a row.  Note that there are more
rows in the table matching with the predicate country in ('Australia') and product ='Xtend
Memory'.  But, just one row is returned as only one cell is inserted by the rule in line 9. Essentially,
RETURN UPDATED ROWS  clause is a limiting clause—it only fetches the rows modified by the rule. 
    子句RETURN UPDATED ROWS也可以应用于使用位置标记的语句。 在列表9-10中,展示了一使用位置标记的规则,插入一行。注意表中有多行匹配谓词country in ('Australia') and product ='Xtend Memory'。但是,只返回了一行,作为按第9行规则插入的唯一单元格。本质上,RETURN UPDATED ROWS子句是一限定子句--它仅取按规则修改的行。
Listing 9-10.  RETURN UPDATED ROWS and UPSERT
  1    select product, country, year, week, sale
  2    from sales_fact
  3    where country in ('Australia') and product ='Xtend Memory'
  4    model  return updated rows
  5    partition by (product, country)
  6    dimension by (year, week)
  7    measures ( sale) 
  8    rules(
  9                 sale [2002, 1] = 0
 10       )
 11 *     order by product,country,year, week
/

PRODUCT           COUNTRY           YEAR       WEEK       SALE
------------        ----------          -----      ----          ----------
Xtend Memory     Australia            2002         1             .00

 

 

 

 

 



已有 0 人发表留言,猛击->>这里<<-参与讨论


ITeye推荐




只有注册用户登录后才能发表评论。


网站导航: