If this is your first visit, be sure to
check out the
FAQ
by clicking the
link above. You may have to
register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.
I am tring to create this function for factorial calculation.
CREATE OR REPLACE FUNCTION fac (n POSITIVE) RETURN INTEGER IS
BEGIN
IF n = 0 THEN
RETURN 1;
ELSIF n = 1 THEN
RETURN 1;
RETURN n * fac(n - 1);
END IF;
END fac;
When i am executing this function as
select FAC(34) from dual
ERROR at line 1:
ORA-01426: numeric overflow
ERROR at line 1:
ORA-06502: PL/SQL: numeric or value error: number precision too large
Can someone help me about the problem with this function.
Thanks
Regards,
Kumar
Is there any other work around to resolve this.. I need to calculate till FAC(100)

.
Thanks in Advance
Regards,
Kumar
Is there any other work around to resolve this.. I need to calculate till FAC(100)

.
Thanks in Advance
Regards,
Kumar
You need to use IBM Mainframe and FORTRAN to calculate FAC(100).
Tamil
SELECT TO_CHAR(fac( 9), '999,999,999') factor_9,
TO_CHAR(fac(10), '999,999,999') factor_10,
TO_CHAR(fac(10) - fac(9),
'999,999,999') factor_diff,
TO_CHAR(fac(30), '999,999,999,999,999,999,999,999,999,999,999') factor_30
FROM dual;
FACTOR_9 FACTOR_10 FACTOR_DIFF FACTOR_30
------------ ------------ ------------ --------------------------------------------
362,880 3,628,800 3,265,920 265,252,859,812,191,058,636,308,480,000,000
You can see that the result grows exponentially. Is this a homework assignment???

RETURN 1;
ELSIF n = 100 THEN
RETURN '93326215443944152681699238856266700490715968264381621468592963895217599993229915608941463976156518286253697920827223758251185210916864000000000000000000000000';
RETURN n * fac(n - 1);
END IF;
END fac;
RETURN 1;
ELSIF n = 100 THEN
RETURN '93326215443944152681699238856266700490715968264381621468592963895217599993229915608941463976156518286253697920827223758251185210916864000000000000000000000000';
RETURN n * fac(n - 1);
END IF;
END fac;
Perhaps you can create a case function to deal with all of the numbers between 30 and 100.
Code:
CCDOTTSVR@vizdev> select fac(99) from dual;
select fac(99) from dual
ERROR at line 1:
ORA-06502: PL/SQL: numeric or value error: character to number conversion error
ORA-06512: at "CCDOTTSVR.FAC", line 10
ORA-06512: at "CCDOTTSVR.FAC", line 10
ORA-06512: at "CCDOTTSVR.FAC", line 10
ORA-06512: at "CCDOTTSVR.FAC", line 10
ORA-06512: at "CCDOTTSVR.FAC", line 10
ORA-06512: at "CCDOTTSVR.FAC", line 10
ORA-06512: at "CCDOTTSVR.FAC", line 10
ORA-06512: at "CCDOTTSVR.FAC", line 10
ORA-06512: at "CCDOTTSVR.FAC", line 10
ORA-06512: at "CCDOTTSVR.FAC", line 10
ORA-06512: at "CCDOTTSVR.FAC", line 10
ORA-06512: at "CCDOTTSVR.FAC", line 10
ORA-06512: at "CCDOTTSVR.FAC", line 10
ORA-06512: at "CCDOTTSVR.FAC", line 10
ORA-06512: at "CCDOTTSVR.FAC", line 10
Thanks for your responses about my doubt..
Slimdave... can you please give some more clear idea about whats the need of putting N = 100 as default value.?..
Tamil.. Can you please throw some lights on your answer " Use IBM or FORTRAN "??
Thanks in advance.
Happy Thanks Giving!!!
Regards,
Kumar
Advertiser Disclosure:
Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.