karanbik...@gmail.com wrote:
I am running a " select " query on my DB2 Table ....which has around
45 columns ..from UNIX prompt . The query output is quiet staggered .
I'd write a small script in my favorite scripting language (such as
Perl) to add a little control over the formatting:
use strict;
use warnings;
use Data::Dumper;
use DBI;
my ($rownum, $dbh, $sth) = (0, undef, undef);
my $query = q{select id integer, firstname, birthday from person};
$dbh = DBI->connect('DBI:DB2:viper', 'db2inst1', '*******') or
die(q{ouch});
$sth = $dbh->prepare($query) or die(q{ouch});
$sth->execute() or die(q{ouch});
while (my $hashref = $sth->fetchrow_hashref()) {
$rownum++;
print qq{$rownum;$_;} . $hashref->{$_} for (keys %{$hashref});
}
$sth->finish() or die(q{ouch});
__END__
$ /usr/bin/perl -wl row_number.pl
1;INTEGER;1
1;BIRTHDAY;2008-04-09 12:08:40.606969
1;FIRSTNAME;bart
2;INTEGER;2
2;BIRTHDAY;2008-04-09 12:08:40.606969
2;FIRSTNAME;lisa
3;INTEGER;3
3;BIRTHDAY;2008-04-09 12:08:40.606969
3;FIRSTNAME;homer