| re: Urgent: Input of values to execute dynamic queries
"Jack Bauer" <giuffsalvo@softhome.net> schreef in bericht
news:5o99l0ldhr5i6p89ibb663gv5pmqolq2gm@4ax.com...[color=blue]
> How can I execute a query which prompt the user for input?
> Something like
> SELECT [target list]
> FROM Table
> WHERE Name=[value input from user]
>
> In Oracle PL/SQL, you use & before variable names to have the SQL*Plus
> ask for input.
> In Postgres PLpg/SQL, I read that the EXECUTE statement should let you
> do something like this, but I tried
> EXECUTE 'SELECT * FROM Employeers WHERE id=' || quote_literal(emp_id);
> and the psql client tells me
> ERROR: syntax error at or near "'SELECT * FROM Employeers WHERE id='"
> at character 9
> LINE 1: EXECUTE 'SELECT *.....
> ^
> Could you help me, please?[/color]
Straight from the manual -7.4 and above-,
you have to prepare before execute:
PREPARE usrrptplan (int, date) AS
SELECT * FROM users u, logs l WHERE u.usrid=$1
AND u.usrid=l.usrid AND l.date = $2;
EXECUTE usrrptplan(1, current_date);
Still, ' EXECUTE usrrptplan ' will not prompt you for input.
HansH |