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
|
CREATE OR REPLACE FUNCTION insertnewcountry(nam character varying, country character varying, descr character varying, nbrcurrebcy integer, is_ac character varying, creby character varying, lang character)
RETURNS void AS
$BODY$
DECLARE
r Integer;
toto Integer := 0;
currencyid Integer:=0;
BEGIN
FOR r IN
EXECUTE 'SELECT c_currency_id FROM c_currency order by c_currency_id'
LOOP
IF toto=nbrcurrebcy THEN
currencyid=r;
ELSE toto:=toto+1;
END IF;
END LOOP;
INSERT INTO c_country (name,countrycode,description,c_currency,is_active,createdby,s_langage)
VALUES (nam,country,descr,currencyid,is_ac,creby,lang) ;
END;
$BODY$
LANGUAGE 'plpgsql' VOLATILE
COST 100; |
Partager