On Tue, Sep 10, 2002 at 06:54:43PM +0530, Agarwal, Ramakant wrote:
> Hi,
> 
>  I did not get any answer to my first question and asking for one more
> doubt.
> 
> The problem is that I have a query some thing like this
> 
> "select <fields> from <table_name>
> where <field_1> in  <set_of_values>"
> 
> The problem is that this query is working fine when there is only one value
> in the set_of_values ,for ex. "a"
> but if I have more than 1 value in the value set then it is not not giving
> any result,for ex "a,b"

Each placeholder represents one value in the statement.  You cannot bind
multiple values to a single placeholder.  You will have to either
interpolate the values directly into the statement, or prepare the
statement with the appropriate number of placeholders.

Here is an approach I have used in this kind of situation, which does a
single prepare for each number of values the appears:

my @sth;

while (my @values = get_values()) {

  $sth[@values] ||= $dbh->prepare('SELECT * FROM mytable WHERE id IN ( ' .
                                  join(', ', ('?') x @values) . ' )');

  $sth[@values]->execute(@values);

  ...

}


Ronald

Reply via email to