环境:
OS:Red Hat Linux As 5
DB:10.2.0.1
perl连接oracle数据库需要安装DBI和DBD for Oracle,相应的软件包可以到下载.
如下是安装过程:
tar zxvf DBI-1.616.tar.gz
cd DBI-1.616
perl Makefile.PL
make
make test
make install
tar zxvf DBD-Oracle-1.27.tar.gz
cd DBD-Oracle-1.27
perl Makefile.PL
make
make test
make install
连接数据库的测试例子:
#!/usr/local/bin/perl
use DBI;
$dbname="oracl";
$user="scott";
$passwd="scott";
$dbh="";
$dbh = DBI->connect("dbi:Oracle:$dbname",$user,$passwd) or die "can't connect to
database ". DBI-errstr;
//连接数据库
$sth=$dbh->prepare("select * from dept");
$sth->execute;
//执行sql语句
while (@recs=$sth->fetchrow_array) {
print $recs[0].":".$recs[1].":".$recs[2]."\n";
//读取记录数据
}
$dbh->disconnect;
//断开连接
--The End--
阅读(6383) | 评论(1) | 转发(0) |