selectcol_arrayref()
$dbh->selectcol_arrayref($sql_statement[, \%attri][, @bind_values])
This returns a reference to an array containing a value in
the first column of each row selected. The SQL statement is given as
the first argument of the function. This can be particularly useful if
the first column is a key field. This function performs
prepare() and
execute() on the SQL statement. Here is an
example:
...
my $sql_stmnt = "SELECT * FROM books";
my $book = $dbh->selectcol_arrayref($sql_stmnt);
foreach my $author_id (@$book){
print "$author_id \n";
}The prepare() method isn’t called to
create a statement handle if the SQL statement is given with this
method, making finish() unnecessary. However,
a statement handle could be given instead. Since the result is an
array reference, it must be deferenced to extract the data (i.e.,
@$book). Using foreach, each
element of the array is extracted, one element per row of the results
set, and the value of each temporarily stored in a variable here
($author_id, the first column of the table).