Well, if you're using the prepared statement only once, it's not clear how much benefit you're getting from it. Nevertheless, if you want to do it that way, you need as many placeholders as values:
my $sql = qq{ SELECT COUNT(*) FROM some_table WHERE some_column IN (} . join(',', (('?') x @values)) . ")";
To me the "better" way would be to prepare the statement once and execute in a loop:
But it sounds like you've already thought of that.my $sql = <<END_SQL; SELECT COUNT(*) FROM some_table WHERE some_column = ? END_SQL my $sth = $dbh->prepare_cached($sql) || die; foreach my $value (@values) { $sth->execute($value); while ($sth->fetch) { # etc.
HTH
In reply to Re: DBI question with placeholders and IN
by VSarkiss
in thread DBI question with placeholders and IN
by dragonchild
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |