Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Factorial of Large Numbers

RijuDec 16 2013 — edited Dec 17 2013

Hi,


I want to calculate factorials of very large numbers. However numbers greater than 83 do not produce the actual results. The below function is the one that I use


create or replace function FN_FACTORIAL(p_num IN INTEGER)

RETURN NUMBER

AS

p_fact NUMBER :=1;

i INTEGER;

BEGIN

     if(p_num = 0)

     then

          return 1;

     else

          for i in 1..p_num

          loop

          p_fact := p_fact*i;

          end loop;

     end if;

     return p_fact;

END;


I know the number data type exceeds its precision and hence it does not work. Can you give me a work around. I cannot use BINARY_INTEGER or BINARY_FLOAT as well since I use Oracle 10g.


Thank you in advance.


Regards,

Prithwish.

This post has been answered by Etbin on Dec 17 2013
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jan 14 2014
Added on Dec 16 2013
12 comments
1,248 views