window xp 下perl 连接oracle11g 脚本实例
perl 在window 连接oracle 实例 perl Conn Oracle on window Demo
************
创建一个perlConnOracleDemo.pl ,内容如下
#!/C:\Perl\bin\perl
#print "hello" ok
#pRint "hello" ;error
use DBI;
$dbname="oracle11";
$user="scott";
$passwd="tiger";
$dbh="";
$dbh = DBI->connect("dbi:Oracle:$dbname",$user,$passwd) or die "can 't connect to database".DBI-errstr;
=pod
连接数据库
=cut
#$sth=$dbh->prepare("select sysdate from dual ;"); #sql语句末尾不能添加分号 error
$sth=$dbh->prepare("select to_char(sysdate,'yyyy-mm-dd') from dual");
$sth->execute;
#执行sql 语句
while(@recs=$sth->fetchrow_array){
print"This is a demo for how perl connnect to oracle on windows32 ! By itlife365.com \r\n";
print"Now is ".$recs[0]."\n";
#读取记录数据
}
#断开数据库连接
$dbh->disconnect;
************
运行结果如下:
Microsoft Windows XP [版本 5.1.2600]
(C) 版权所有 1985-2001 Microsoft Corp.
C:\Documents and Settings\Administrator>cd /d D:\me\perl
D:\me\perl>perl perlConnOracleDemo.pl
This is a demo for how perl connnect to oracle on windows32 ! By itlife365.com
Now is 2012-12-18
D:\me\perl>