I don't think this is a case to use explicit bind vars.
Assuming that you want to copy some columns from table1 to a new table2 based upon some parameters in table1 that won't even appear in table2, here is some code that was adapted from choroba's post:
#!/usr/bin/perl
use warnings;
use strict;
use feature qw{ say };
use DBI;
my $db = 'DBI'->connect('dbi:SQLite:;db=:memory:', "", "");
$db->do('CREATE TABLE t1 (id INT, name TEXT, quantity INT)');
$db->do('CREATE TABLE t2 (id INT, quantity INT)');
my $populate = $db->prepare(
'INSERT INTO t1 (id, name, quantity) VALUES (?, ?, ?)');
$populate->execute(@$_) #some test cases that don't start with 'J'
for [ 1, 'John', 12 ],
[ 2, 'Jane', 14 ],
[ 3, 'Jack', 16 ],
[ 5, 'Joe', 22 ],
[ 5, 'bobo', 33 ],
[ 23,'xyz', 44 ],
[ 6, 'Josh', 27 ];
my $copy = $db->prepare("INSERT INTO t2 (id, quantity)
SELECT id, quantity
FROM t1
WHERE name LIKE ? AND id > ?");
$copy->execute('J%',2);
my $verify_t2 = $db->prepare('SELECT * FROM t2');
$verify_t2->execute;
my @row;
say "@row" while @row = $verify_t2->fetchrow_array;
__END__
Prints:
3 16
5 22
6 27
|