Hi Monks,
I tried to retrieve only one column from db every time and combine each time result into an array.
I know I can use "selectcol_arrayref" to do this job, and it works. However, I kind of doubt its performance. I tried to use a statement handle with a place holder to do it. so I can prepare a query first, and each loop of execute will return all the rows of one single column. Just didn't find such info anywhere. could someone give me some hints? thank you.foreach $id (@id){ $statement = qq{select val1 from tb11 where x=$id}; $col_ref = $dbh->selectcol_arrayref($statement); push @ary,$col_ref; }
above is what I did, which actually just return the values of one column.
now, I want to put the query statement out of the loop, and use something like $sth->prepare(qq{select val1 from tbl1 where x= ?}), then in the loop try to do $sth->execute($id) to get the value. But I want to get the whole column values at once, not just reference to array of reference. I am wondering if there is a function for statement handle to return all the values for a single column by just one call.In reply to How to use Perl DBI to select just on column of db by lightoverhead
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |