sequence .nextval evaluating twice when used inside an INSERT cmd



Call anyone spot the difference in the newsessionid value in these two examples ?

#1 :
	create procedure MM_createSessionEntry
	(
	...
	)
	as declare
	newsessionid bigint not null not default ;
	begin
	INSERT INTO my_table
	(entryID,
	...
	)
	VALUES
	(entryidkey.nextval,
	...;

	newsessionid = entryidkey.currval;
	return newsessionid;

#2 :

	create procedure MM_createSessionEntry
	(
	...
	)
	as declare
	newsessionid bigint not null not default ;
	begin
	newsessionid = entryidkey.nextval;
	INSERT INTO my_table
	(entryID,
	...
	)
	VALUES
	(newsessionid ,
	...;

	return newsessionid;


Ok, here's the spoiler -

In the first the newsessionid being called twice whereas in the second it gets called once (the expected behaviour). It seems that if you use a sequence directly as a parameter it gets stepped twice. Not using it as a paramter directly solves the issue. Coming from a pure programming background (ie. non-DB) I can't see why this is.

Morgan.
.