Aim:
To find the factorial number of given values using SQL commands.
Algorithm:
Step 1: Start the program.
Step 2: Declare the values in declare block.
Step 3: Execute the SQL commands in begin end block.
Step 4: Get the output.
Step 5: Stop the process.
Program
DECLARE
num number;
factorial number;
FUNCTION fact(x number)
RETURN number
IS
f number;
BEGIN
IF x=0 THEN
f:=1;
ELSE
f:=x*fact(x-1);
END IF;
RETURN f;
END;
BEGIN
num:=6;
factorial:=fact(num);
dbms_output.put_line(' Factorial '||num||' is '||factorial);
END;
OUTPUT:
Factorial 6 is 720
Post a Comment