|
Do we have any function which calulates Factorial value. Factorial definition: n* n-1 * n-2 * ...... * 1 For example: 5! = 5*4*3*2*1 I didn't find any function for this. I am planning to create a PL/SQL function for this. Any ideas are welcome.
(comments are locked)
|
|
SELECT ROWNUM, EXP(SUM(LN(ROWNUM)) OVER (ORDER BY ROWNUM)) FACTORIAL FROM USER_OBJECTS WHERE ROWNUM < 10
(comments are locked)
|
|
Don Burleson dives into factorials: A Zillion Ways to Do Factorials He mentions that the exp(sum(ln(rownum))) technique doesn't work in all cases. Ah, I see he also mentions that his information is drawn from this book: SQL Design Patterns by Vadim Tropashko Probably the best way is just to create your own function. I found one at:
Caution! Not tested. They also show a way to do it in SQL. This question reads like a college level course homework assignment :)
Dec 17 '09 at 11:37 PM
HillbillyToad
You know, I think you're right. It's probably because of the factorials. College programming (I go back before "Computer Science" degrees) homework always involved some unrealistic problem that involved some sort of math that we've never even seen since college... like factorials!
Dec 18 '09 at 02:08 AM
KillerDBA
Not exactly Kind of college work. But I needed to do this for my project requriement. I know that we can do this by definig PL/SQL procedure. But I thought of finding some better ways to do this. So I found few good ones here. Thanks to everyone.
Dec 18 '09 at 05:10 PM
OraLearner
(comments are locked)
|
|
Check out this query. I found the query over internet. select count(*) FACTORIAL from ( select level b from (select level n from dual connect by level <= &x ) YourTable connect by nocycle n != prior n )where b = &x Replace &x with factorial value. But this query seems to be very slow. Only to show another way of doing this.
(comments are locked)
|

