zzia88(at)gmail(dot)com writes:
> CREATE OR REPLACE FUNCTION FACTORIAL(IN NUM BIGINT,OUT FACT BIGINT) AS $$
> DECLARE
> FACT BIGINT;
> BEGIN
> FOR I IN REVERSE 1..NUM LOOP
> FACT:=FACT*I;
> END LOOP;
> END;
> $$ LANGUAGE plpgsql;
> SELECT* FROM FACTORIAL(5);
> IT SHOWING NULL VALUE...
Yes. You didn't initialize FACT to something non-null (like, say, 1)
and multiplying null by anything will produce another null.
I think the REVERSE in your loop is wrong, too.
regards, tom lane