On Wed, 2004-08-18 at 08:14, Xinyu Wen wrote:
> I have a query like this:
> 
> select a from some_table where b in (?);
> 
> I neet to bind 1000 items for b which likes:
> 
> select a from some_table where b in ('abc','bcd','acd',....x1000);
> 
> how can I bind this many parameters without actually put 1000 "?" in
> the sql statement and write 1000 "sth->bind_param" in my code?



my $sql = q{select a from my_table where b in (};

my @args = (
   qw {
      one two first fast excelsior random kind
      give dog bone
   }
);

$sql .= join(q{,},split(//,"?" x @args)) . ')';

print "$sql\n";

my $sth=$dbh->prepare($sql);
$sth->execute(@args);



Just because you can though, doesn't mean you should.

Test the performance of the generated SQL.

If you have many sets of parameters with differing 
numbers of arguments, and the SQL is executed often,
you may wish to discuss this with your friendly DBA.

Jared


Reply via email to