Login or Sign up Help | Site Map
Connecting Tech Pros Worldwide

Urgent: Input of values to execute dynamic queries

Question posted by: Jack Bauer (Guest) on November 23rd, 2005 02:04 AM
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?
Would you like to answer this question?
Sign up for a free account, or Login (if you're already a member).
HansH's Avatar
HansH
Guest
n/a Posts
November 23rd, 2005
02:04 AM
#2

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








 
Not the answer you were looking for? Post your question . . .
182,081 Experts ready to help you find a solution.
Sign up for a free account, or Login (if you're already a member).

  • Didn't find the answer you were looking for?
    Post Your Question
  • Top Community Contributors