By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
428,558 Members | 1,603 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 428,558 IT Pros & Developers. It's quick & easy.

Urgent: Input of values to execute dynamic queries

P: n/a
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?
Nov 23 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
"Jack Bauer" <gi********@softhome.net> schreef in bericht
news:5o********************************@4ax.com...
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?

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



Nov 23 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.