Write a procedure and call it into main pl/sql program to find a factorial of a number.
/*creating the procedure to find the factorial of a number*/
CREATE PROCEDURE
my_factorial_procedure(IN my_number INT)
BEGIN
DECLARE my_result INT;
DECLARE j INT;
SET my_result=1;
SET j=1;
WHILE j<=my_number DO
SET my_result=my_result*j;
SET j=j+1;
END WHILE; SELECT my_number AS Number,my_result AS Factorial;
END;
/*we invoke this procedure by passing the value which we want to get the factorial as an argument*/
CALL my_factorial_procedure(2);
Comments
Leave a comment