pg.ddx.io  pgsql-docs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Kuti Attila <attika@elender.hu>
To: questions@postgresql.org
To: docs@postgresql.org
Subject: cursors in plpgsql function??
Date: Thu, 5 Aug 1999 11:36:18 +0200
Message-ID: <199908050934.LAA24411@mail.elender.hu> (raw)

Hi!

I have problem with declaring a cursor for a query in a plpgsql. I got 
compile error, and parse error at or near cursor.

Here my function for a trigger:
What can be the problem?

Thanks a lot
Attila

create function p_kotogep() returns opaque  as '
		
       declare
		ajanlid  ajanlati_konyv_p.ajanlat_id%TYPE;
		userid   felhasznalo.user_id%TYPE;
		megidop  timestamp;
		termekid termek.termek_id%TYPE;
		menny	 portfolio.szabad_db%TYPE;
		arr	 portfolio.szabad_db%TYPE;
		iran	 ajanlati_konyv_p.irany%TYPE;
		erv	 timestamp;
		hany	int4;
		piar	bool;

		aktar   termek.arfolyam%TYPE;


	begin work;
		select count(ajanlat_id) into hany from 
ajanlati_konyv_p;

-- 	SOMEWHERE HERE I GET ALWAYS ERROR
	declare ajanlatok cursor for select * from 
ajanlati_konyv_p;

	for i in 1..hany loop
	
		fetch next from ajanlatok into
			ajanlid, userid, megidop, termekid, 
menny, arr, piar, iran, erv;


		aktar= p_aktar(termekid);

	if setup_olv(1) then		-- arjegyzovel 
jatszunk

	  if iran = 1 then		-- vetel

		if aktar <= arr then

		insert into kotes_naplo_p (vevo_id, 
elado_id, termek_id, ar, mennyiseg, szabad_valt)
		 values (userid, 1, termekid, arr, menny, 
trktsg (menny, arr, 1) );

		delete from ajanlati_konyv_p where 
ajanlati_id = ajanlid;
		else
		
		end if;
	   
	  else
		if aktar >= arr then
		insert into kotes_naplo_p (vevo_id, 
elado_id, termek_id, ar, mennyiseg, szabad_valt)
		 values (1, userid, termekid, arr, menny, 
trktsg (menny, arr, 1) );

		delete from ajanlati_konyv_p where 
ajanlati_id = ajanlid;

		else

		end if;
	  end if;


	end if ;	-- arjegyzovel jatszunk vege
	end loop;
	close ajanlatok;
	commit work;

	return NULL;
;
  
	' language 'plpgsql';
trigger paj_kot on ajanlati_konyv_p;
trigger paj_kot
       after  insert  on ajanlati_konyv_p
       for each row 
       execute procedure p_kotogep();



attika@elender.hu
http://www.bke.hu/~attika



Message-ID: <199908050934.LAA24411@mail.elender.hu>
Permalink:  ../199908050934.LAA24411@mail.elender.hu/
Also on:    postgresql.org/message-id/199908050934.LAA24411@mail.elender.hu

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-docs@postgresql.org
  Cc: attika@elender.hu, questions@postgresql.org, docs@postgresql.org
  Subject: Re: cursors in plpgsql function??
  In-Reply-To: <199908050934.LAA24411@mail.elender.hu>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox