1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
|
CREATE TABLE truc
(
id_truc integer,
sousid_truc integer,
nom_truc text
)
WITH (
OIDS=FALSE
);
ALTER TABLE truc OWNER TO postgres;
CREATE OR REPLACE FUNCTION obtenirTousLesTrucs() RETURNS SETOF tructest AS
$BODY$
DECLARE
r tructest%rowtype;
BEGIN
FOR r IN SELECT * FROM truc
WHERE id_truc > 0
LOOP
-- quelques traitements
RETURN NEXT r; -- renvoie la ligne courante du SELECT
END LOOP;
RETURN;
END
$BODY$
LANGUAGE 'plpgsql' ;
CREATE OR REPLACE FUNCTION obtenirTousLesTrucs2() RETURNS integer AS
$BODY$
DECLARE
r tructest%rowtype;
test integer;
BEGIN
FOR r IN SELECT * FROM obtenirTousLesTrucs()
LOOP
-- quelques traitements
INSET INTO machin (montext) VALUES (r.nom_truc);
END LOOP;
RETURN;
END
$BODY$
LANGUAGE 'plpgsql' ;
SELECT * FROM obtenirTousLesTrucs2(); |