Thread: EXECUTE command in stored procedure

EXECUTE command in stored procedure

From
"Arunagiri K"
Date:
Dear All,

How can I use EXCEUTE command in stored procedures?
When using like this

EXECUTE 'SELECT INTO REGNO REG_NO FROM ADMISSION WHERE SNAME = ' || STUDNAME ;

STUDNAME is a local variable;

I am getting error like this

ERROR:  syntax error at or near "INTO" at character 8

How can I solve this.

Regards,
Arunagiri.K

Re: EXECUTE command in stored procedure

From
"Guy Rouillier"
Date:
Arunagiri K wrote:
> Dear All,
>
> How can I use EXCEUTE command in stored procedures?
> When using like this
>
> EXECUTE 'SELECT INTO REGNO REG_NO FROM ADMISSION WHERE SNAME = ' ||
> STUDNAME ;
>
> STUDNAME is a local variable;
>
> I am getting error like this
>
> ERROR:  syntax error at or near "INTO" at character 8
>
> How can I solve this.

You don't mention which version of PostgreSQL you are using, or which
stored procedure language.  I'll assume 8.1.x and PL/pgSQL.  See section
36.6 in the documentation.  Specifically, 36.6.5 says:

"SELECT INTO is not currently supported within EXECUTE."

However, if I'm understanding what you are trying to do, you shouldn't
need the EXECUTE at all.  Doing a simple SELECT INTO should work for
you.  Note also that since you are only retrieving a single value, you
can also avoid INTO altogether with something like:

REGNO := (select regno from admission where sname = myname);

--
Guy Rouillier