[oracle@jhoa 3]$ perl dbi.pl sh-3.2$ c
sh: c: command not found
sh-3.2$ cat dbi.pl
#!/usr/bin/perl
use strict;
use DBI;
my $dbName = 'orcl';
my $dbUser = 'test';
my $dbUserPass = 'test';
my $dbh = DBI->connect("dbi:Oracle:$dbName", $dbUser, $dbUserPass) or die "can't connect to database ";
my $hostSql = qq{select table_name,tablespace_name,status from user_tables};
#你用print是打印sql语句和sth对象,看到这个说明没有错误
#另外,perl中打印对象或其它复杂数据结构最好用use Data::Dumper;print Dumper $obj;这种形式,要不你就只能看到HA
#$dbh->prepare($sql),只是生成了一个statement handle对象而已,该对象调用execute后,通过它的fetchrow_array()就
#
my $sql = "select * from v\$lock";
my $sth = $dbh->prepare($sql);
print "$sth..\n";
$sth->execute();
while (my @arr = $sth->fetchrow_array()){
print "@arr\n";
}
$sth->finish;
sh-3.2$ perl dbi.pl