|
同样的算法用model语句来实现。- with targ as (select 100 arg from dual)
- ,t as (select level d from targ connect by level<=arg)
- ,t2 as (select tr.d r, tc.d c, 1 num from t tr, t tc)
- ,t3 as (select r,c, num
- from t2
- MODEL
- DIMENSION BY (r,c)
- MEASURES (num)
- RULES update
- (
- num[any, any] order by r , c
- = case when cv(r)>1 and cv(c)>1 and cv(r)<cv(c) then num[cv(r),cv(r)]
- when cv(r)>1 and cv(c)>1 and cv(r)=cv(c) then 1+num[cv(r),cv(c)-1]
- when cv(r)>1 and cv(c)>1 and cv(r)>cv(c) then num[cv(r)-cv(c),cv(c)]+num[cv(r),cv(c)-1]
- else num[cv(r),cv(c)] end
- ) order by r , c)
- select r,c,num from t3,targ where r=arg and c=arg-1
复制代码 R C NUM
---------- ---------- ----------
100 99 190569291
Executed in 0.078 seconds |
|