First, your @array_num variable is getting populated with a single value the way that your code is written. Try this:
my @array_num = qw/123 456 345 459 234/;
Second, you never set $n1 and $n2 to anything. I'll assume that you want them to be the first and second values in your array.
my $n1 = $array_num[0]; my $n2 = $array_num[1];
Third, you really should be using placeholders (or bind parameters) in your $sql statement to safeguard against SQL injection attacks. This is not much of a problem in the statements as you've presented them, but it's really a good practice to get into. Read more about SQL placeholders.
So, finally, we have this:
my @array_num = qw/123 456 345 459 234/; my $n1 = $array_num[0]; my $n2 = $array_num[1]; my $sql= " SELECT tb.num1, tb.num2 FROM MYTABLE tb WHERE tb.num1 = ? AND tb.num2 = ?"; $sql->execute($n1, $n2);
EDIT: Per trammell's reply below.
In reply to Re: Array, SQL Question!
by Yendor
in thread Array, SQL Question!
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |