#!/bin/perl
use DBI;
$dbname = "JSBSS_TEST";
$user = "oss";
$passwd = "as1a1nf0";
$dbh = "";
$dbh = DBI->connect( "dbi:Oracle:$dbname", $user, $passwd )
or die "Can't connect to Oracle database: $DBI::errstr/n";
{
#==================================
#选择数据方法1--简单sql
#==================================
#连接数据库
my $sth = $dbh->prepare("select table_name from user_tables where rownum < 10")
or die "Can't prepare SQL statement: $DBI::errstr/n";
$sth->execute or die "Can't execute SQL statement: $DBI::errstr/n";
#读取记录数据
while ( my @recs = $sth->fetchrow_array ) {
print "@recs/n";
}
warn "Data fetching terminated early by error: $DBI::errstr/n"
if $DBI::err;
}
$dbh->disconnect or warn "Disconnection failed: $DBI::errstr/n";
#断开连接
exit 0;