PostgreSQL Loop – End Loop

LOOP

Syntax and examples of conditional Loop – End Loop.

CREATE OR REPLACE FUNCTION 
	get_loop(in p_id numeric) 
RETURNS varchar AS $$
DECLARE
	j numeric;
	v_name varchar(50);	
BEGIN
	j:=0;
	FOR i in 1..p_id LOOP
		j:=j+1;
		v_name:='The count is: '||j;
	END LOOP;	
    return v_name;
END;
$$ LANGUAGE 'plpgsql';