經典SQL-1

wangkxxe發表於2009-07-21

不用函式實現N的階乘

SELECT MAX(prod)
FROM (SELECT prod
FROM ( SELECT ROWNUM rn
FROM DUAL
CONNECT BY ROWNUM<=6
)
MODEL RETURN UPDATED ROWS
DIMENSION BY (rn)
MEASURES (rn rn2,1 prod )
RULES (
prod[any] order by rn=DECODE(rn2[cv()],1,1,prod[cv()-1]*rn2[cv()])
)
)

[@more@]

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/12801008/viewspace-1024357/,如需轉載,請註明出處,否則將追究法律責任。

相關文章