Simple While LOOP : While « Postgre SQL « PostgreSQL






Simple While LOOP


postgres=#
postgres=# CREATE FUNCTION "count_by_two" (integer) RETURNS integer AS '
postgres'#      DECLARE
postgres'#           userNum ALIAS FOR $1;
postgres'#           i integer;
postgres'#      BEGIN
postgres'#           i := 1;
postgres'#           WHILE userNum < 20 LOOP
postgres'#                 i = i+1;
postgres'#                 return userNum;
postgres'#           END LOOP;
postgres'#
postgres'#      END;
postgres'#    ' LANGUAGE 'plpgsql';
CREATE FUNCTION
postgres=#
postgres=# select count_by_two(12);
 count_by_two
--------------
           12
(1 row)

postgres=#
           
       








Related examples in the same category

1.Using the WHILE loop