Perl脚本访问Greenplum数据库安装指导(三)

2015-07-24 10:52:28 · 作者: · 浏览: 21
assword 密码 unless(@ARGV == 3) { die "Usage: $0 dbname dbuserpassword\n"; } #接收传入的参数 my$dbname = $ARGV[0]; my$dbuser = $ARGV[1]; my$password =$ARGV[2]; my $sth; my$col_num; my @cols; my@row_ary; my $i; my $dbh =DBI->connect("dbi:ODBC:$dbname",$dbuser,$password, {AutoCommit => 0, RaiseError => 0, PrintError => 0,} ) or die"Can't connect to Greenplum database: $DBI::errstr\n"; $sth =$dbh->prepare("select * from hello1"); $sth->execute(); # Thenumber of columns $col_num= $sth->
{NUM_OF_FIELDS}; # outputcolumns @cols = @{$sth->{NAME}}; printjoin("\t",@cols),"\n"; while (@row_ary = $sth->fetchrow_array ) { for($i=0; $i<$col_num; $i++){ my $len = length $cols[$i] ; printf "%-${len}s\t",$row_ary[$i]; } print "\n"; } $sth->finish; $dbh->disconnect(); exit 0;

(2) 测试过程:

linux-82:/etc/unixODBC # perl hellokitty.plGreenplumDSN noas noas

id name

2 hello2

1 hello1

3 hello3

?