smith smith - 3 years ago 240
Perl Question

perl DBI and placeholders

I have this query

select * from table where ID in (1,2,3,5...)

How is it possible to build this query with the DBI using placeholders ?

for example :

my @list = (1, 2, 3, 4, 5);
my $sql = "select * from table where ID in (?)";


What argument should I send to execute? Is it a list or a string separated by
or something else?

Answer Source

This should build your query dynamically according to the number of items in your array

my @list =(1,2,3,4,5);
my $sql ="select * from table where ID in (@{[join',', ('?') x @list]})";
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download