Connor and Chris will both be at AI World from October 12 to October 17 , the premier Oracle conference of 2025. If you're in Vegas, please come say Hi or pop into our sessions
Thanks for the question, Sudarshan.
Asked: February 02, 2017 - 2:29 pm UTC
Last updated: November 02, 2020 - 2:43 am UTC
Version: 11g
Viewed 10K+ times! This question is
SQL> create or replace 2 function factorial ( 3 n positive 4 ) return positive 5 is 6 begin 7 if n = 1 then 8 return n; 9 else 10 return n * factorial(n-1); 11 end if; 12 end; 13 / Function created. SQL> SQL> set serverout on SQL> begin 2 for i in 1..5 loop 3 dbms_output.put_line(i || '! = ' || factorial(i)); 4 end loop; 5 end; 6 / 1! = 1 2! = 2 3! = 6 4! = 24 5! = 120 PL/SQL procedure successfully completed.
Shyamal, October 24, 2020 - 2:51 am UTC
marc, October 30, 2020 - 7:03 pm UTC
CREATE OR REPLACE FUNCTION factorial(n POSITIVE) RETURN POSITIVE IS BEGIN factorial(n - 1); IF n = 1 THEN RETURN n; ELSE RETURN n * factorial(n - 1); END IF; END; /
Check out more PL/SQL tutorials on our LiveSQL tool.
PL/SQL reference manual from the Oracle documentation library