Chinaunix首页 | 论坛 | 博客
  • 博客访问: 537086
  • 博文数量: 154
  • 博客积分: 4055
  • 博客等级: 上校
  • 技术积分: 1381
  • 用 户 组: 普通用户
  • 注册时间: 2006-04-01 14:26
文章分类

全部博文(154)

文章存档

2014年(2)

2013年(2)

2011年(2)

2010年(11)

2009年(9)

2008年(35)

2007年(22)

2006年(71)

我的朋友

分类:

2009-05-29 13:16:40

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
阅读(766) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~