Perl连接Oracle数据库

来源:百度文库 编辑:神马文学网 时间:2024/04/23 22:51:59
Perl连接Oracle数据库http://www.51cto.com 2005-09-09 11:48 http://beta.xmu.cn/ 上次讲了在linux下安装Oracle,安装完之后可以用netac来配置远程数据库的本地命名。

要在perl下面连接oracle数据库,首先必须安装DBI和DBD for Oracle。

下面是一段perl程序

#!/usr/bin/perl

use DBI;

$dbname="oralce";

$user="user";

$passwd="password";

$dbh="";

$dbh = DBI->connect("dbi:Oracle:$dbname",$user,$passwd) or die "can‘t connect to

database ". DBI-errstr;

//连接数据库

$sth=$dbh->prepare("select * from tDevice");

$sth->execute;

//执行sql语句

while (@recs=$sth->fetchrow_array) {

rint $recs[0].":".$recs[1].":".$recs[2]."\n";

//读取记录数据

}

$dbh->disconnect;

//断开连接