Find the factorial of a number in pl/sql

Given a number, your task to print the factorial of that number using pl/sql.


Input : 5
Output : 120

5! = 5 * 4 * 3 * 2 * 1 = 120

Input : 4
Output : 24

Basic structure of pl/sql block

-- declare all the variables

begin  -- for start block
-- make a program here

end -- for end block

The program of factorial of a number in pl/sql is given below:

[sourcecode language=”SQL”]

— it gives the final answer after computation
fac number :=1;

— given number n
— taking input from user
n number := &1;

— start block

— start while loop
while n > 0 loop

— multiple with n and decrease n’s value
end loop;
— end loop

— print result of fac

— end the begin block


Output:(if given input as 5)


My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using or mail your article to See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

Article Tags :
Practice Tags :

Be the First to upvote.

Please write to us at to report any issue with the above content.