Urgent: Input of values to execute dynamic queries

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jack Bauer

    Urgent: Input of values to execute dynamic queries

    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(e mp_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?
  • HansH

    #2
    Re: Urgent: Input of values to execute dynamic queries

    "Jack Bauer" <giuffsalvo@sof thome.net> schreef in bericht
    news:5o99l0ldhr 5i6p89ibb663gv5 pmqolq2gm@4ax.c om...[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(e mp_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







    Comment

    Working...