Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

CREATE OR REPLACE PROCEDURE factorial (n IN NUMBER)

IS
v NUMBER :=1;
BEGIN
FOR i IN 1..n
LOOP
dbms_output.put_line(i);
v := v * i;
END LOOP;

DBMS_OUTPUT.put_line (v);
END;
/
select exp(sum(ln(1*level))) factorial from dual
connect by level<=6 ---- Give Required Factorial Number Here

SQL> with t (c1, c2) as


(
select 2, 1 from dual union all
select c1+1, c1*c2 from t where c1 <= 10
)
--
--
select c1-1 "n", c2 "n!" from t
/
n n!
---------- ----------
1 1
2 2
3 6
4 24
5 120
6 720
7 5040
8 40320
9 362880
10 3628800

10 rows selected.

declare

-- declare variable first = 0,

-- second = 1 and temp of datatype number

first number := 0;

second number := 1;

temp number;
n number := 5;

i number;

begin

dbms_output.put_line('Series:');

--print first two term first and second

dbms_output.put_line(first);

dbms_output.put_line(second);

-- loop i = 2 to n

for i in 2..n

loop

temp:=first+second;

first := second;

second := temp;

--print terms of fibonacci series

dbms_output.put_line(temp);

end loop;

end;

--Program End

Output:

0 1 1 2 3 5

You might also like