CREATE OR REPLACE FUNCTION power(x IN NUMBER, n IN NUMBER) RETURN NUMBER IS
result NUMBER := 1; -- Variable to store the result
i NUMBER := 0; -- Loop counter
BEGIN
FOR i IN 1..n LOOP
result := result * x;
END LOOP;
RETURN result;
END;
/
declare
a integer:=&a;
b integer:=&b;
begin
dbms_output.put_line('factorial :'||power(a,b));
end;
/
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter