Plpgsql and cursors - Mailing list pgsql-general

From olivier ALLAIN
Subject Plpgsql and cursors
Date
Msg-id 387347B5.4E61AC7B@celya.fr
Whole thread Raw
List pgsql-general
hi,

i'm testing postgresql database and especially the procedural language plppgsql.
I want to 'translate' an Oracle pl/sql procedure which looks like this :
 

create function cal_montant_ht_com(id_com int8) RETURN NUMBER is
cursor cur1 is select quantite_detcom,prix_ht_detcom from detail_commandes where fk_commande_detcom=id_com;
quantite_detcom  NUMBER;
prix_ht_detcom  NUMBER;
montant_ht   NUMBER;
 begin
montant_ht:=0;
OPEN cur1;
LOOP
FETCH cur1 INTO quantite_detcom, prix_ht_detcom;
EXIT WHEN cur1%notfound;
montant_ht:=montant_ht+(quantite_detcom*prix_ht_detcom);
END LOOP;
close cur1;
RETURN (montant_ht);
end cal_montant_ht_com;
I try this :

create function cal_montant_ht_com(int8) RETURNS float8 AS '

  cursor cur1 is select quantite_detcom,prix_ht_detcom from detail_commandes where fk_commande_detcom=$1;
  quantite_detcom int8;
  prix_ht_detcom float8;
  montant_ht float8;
 begin
  montant_ht:=0;
  OPEN cur1;
  LOOP
   FETCH cur1 INTO quantite_detcom, prix_ht_detcom;
   EXIT WHEN cur1%notfound;
   montant_ht:=montant_ht+(quantite_detcom*prix_ht_detcom);
  END LOOP;
  close cur1;
  RETURN montant_ht;
 END;
' LANGUAGE 'plpgsql';

but it still doesn't work (error at line 2, the declaration of the cursor) and  haven't any other idea;

Could you help me ?

olivier Allain.
 

pgsql-general by date:

Previous
From: Luis Bezerra
Date:
Subject: (no subject)
Next
From: Jose Soares
Date:
Subject: Re: [GENERAL] Import table from MS Access?