1、这里比较重要的就是安装好了DBD就可以了
perl MakeFile.PL
make
make test
make install(可能需要root用户来操作)
3、链接代码就简单了。
#!/usr/local/bin/perl
use DBI;
$dbname="db09";
$dbuser="dsg";
$dbpasswd="dsg";
$dbh = DBI->connect("dbi:Oracle:$dbname",$dbuser,$dbpasswd) or die("DB connect error!n");
print "connect to db09 is ok!\n";
$sql = "select rowid,a.* from test1 a where rownum<11";
$sth = $dbh->prepare($sql);
print "dbh->prepare sql is ok!\n";
$sth->execute() or die("error!");
print "execute sql is ok!\n";
open (OUTPUT,">output.txt")
or die "Could't write text into output.txt!\n";
while (@recs=$sth->fetchrow_array) {
print OUTPUT $recs[0]."\t".$recs[1]."\t".$recs[2]."\n";
}
close(OUTPUT);
$sth->finish;
$dbh->disconnect();
exit 0;
[RHEL3]:[/templv/zl9/sc]$ ./p.pl
connect to db09 is ok!
dbh->prepare sql is ok!
execute sql is ok!
[RHEL3]:[/templv/zl9/sc]$ cat output.txt
AAAIG2AADAAABPcAAA 65793 name1-65793
AAAIG2AADAAABPcAAB 65794 name1-65794
AAAIG2AADAAABPcAAC 65795 name1-65795
AAAIG2AADAAABPcAAD 65796 name1-65796
AAAIG2AADAAABPcAAE 65797 name1-65797
AAAIG2AADAAABPcAAF 65798 name1-65798
AAAIG2AADAAABPcAAG 65799 name1-65799
AAAIG2AADAAABPcAAH 65800 name1-65800
AAAIG2AADAAABPcAAI 65801 name1-65801
AAAIG2AADAAABPcAAJ 65802 name1-65802
阅读(795) | 评论(0) | 转发(0) |