Search notes:

Perl module DBI: selectcol_arrayref

By default, the method selectcol_arrayref returns a ref to a list containing the elements of the first column of the result set of the select statement:
#!/usr/bin/perl
use warnings;
use strict;

use DBI;

unlink 'the.db' if -e 'the.db';
my $dbh = DBI->connect('dbi:SQLite:dbname=the.db') or die "Could not create the.db";

$dbh -> do('create table tab(col1, col2, col3)');

my $sth = $dbh -> prepare('insert into tab values (?, ?, ?)');
$sth -> execute('foo', 'one'  , 'abc');
$sth -> execute('bar', 'two'  , 'def');
$sth -> execute('baz', 'three', 'ghi');

for (@{$dbh -> selectcol_arrayref('select col1 from tab')}) {
  print "$_\n";
}
#
# foo
# bar
# baz
Github repository PerlModules, path: /DBI/selectcol_arrayref.pl
Multiple columns can be selected, however, the result set is not row or column based at all:
#!/usr/bin/perl
use warnings;
use strict;

use DBI;

unlink 'the.db' if -e 'the.db';
my $dbh = DBI->connect('dbi:SQLite:dbname=the.db') or die "Could not create the.db";

$dbh -> do('create table tab(col1, col2, col3)');

my $sth = $dbh -> prepare('insert into tab values (?, ?, ?)');
$sth -> execute('foo', 'one'  , 'abc');
$sth -> execute('bar', 'two'  , 'def');
$sth -> execute('baz', 'three', 'ghi');

my $colref =  $dbh -> selectcol_arrayref('select * from tab', {Columns=>[1, 2]});

for my $elem (@$colref) {
  print $elem, "\n";
}
# 
# foo
# one
# bar
# two
# baz
# three
Github repository PerlModules, path: /DBI/selectcol_arrayref-multiple-columns.pl

See also

Perl Module DBI, select_all* methods
Perl module DBI

Index