Factorial in SQL

Example for versions Oracle 10g SQL, Oracle 11g SQL

This example calculates factorials iteratively by means of PL/SQL.

declare
    n    number := 0;
    f    number := 1;
begin
    while (n<=16)
    loop
        dbms_output.put_line(n || '! = ' || f);
        n := n+1;
        f := f*n;
    end loop;
end;