折腾了两天,终于在HP-UX上装好了Oracle Instant Client 和Perl 的 DBD::Oracle,现在记录安装过程和注意点如下。 0) 安装环境 我的OS和Perl的环境是: # uname -a HP-UX SVSAF006 B.11.23 U ia64 2789703618 unlimited-user license
# perl -version This is perl, v5.8.3 built for IA64.ARCHREV_0-thread-multi 。。。。。。 Binary build 809 provided by ActiveState Corp. ActiveState is a division of Sophos. 。。。。。。 1) 安装Oracle Instant Client 我的Perl程序要访问Oracle DB,所以先要装Oracle客户端,我装的是版本是instantclinet 10.2.0.2 for hpux ia64, 需要basic,sdk,sqlplus三个包,如下: instantclient-basic-hpux-ia64-64-10.2.0.2-20060428.zip instantclient-sdk-hpux-ia64-64-10.2.0.2-20060428.zip instantclient-sqlplus-hpux-ia64-64-10.2.0.2-20060428.zip
1.3)测试数据库连接 # sqlplus [url=mailto:yourdbusername/yourdbpassword@YOURDB]yourdbusername/yourdbpassword@YOURDB SQL*Plus: Release 10.2.0.2.0 - Production on Thu Dec 20 16:46:04 2007 Copyright (c) 1982, 2005, Oracle. All Rights Reserved. Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - 64bit Production With the Partitioning, OLAP and Data Mining options SQL> select sysdate from dual; SYSDATE --------- 20-DEC-07
SQL> quit Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - 64bit Production 至此,Oracle客户端搞定!
#!/usr/bin/perl -w # use DBI; &Main(); sub Main{ &selectData(); } sub RFTDB_Connect { my $conn = dbi:Oracle:host=ip of Oracel server ;sid=your database name; my $connUser="yourdbusername"; my $connPass="youdbpassword"; if(!$RFT_Parser_Common_DBConnection ){ eval{ $RFT_Parser_Common_DBConnection = DBI->connect($conn,$connUser,$connPass) or die $DBI::errstr; }; if($@ ){ print "Error: $@ \n"; exit(1); } } return $RFT_Parser_Common_DBConnection; } sub RFTDB_Disconnect { if($RFT_Parser_Common_DBConnection ){ $RFT_Parser_Common_DBConnection->disconnect(); $RFT_Parser_Common_DBConnection =0; }else{ print "DB is not opened, does nonthing."; } } sub selectData{ my $hDB=""; my $recs=""; $hDB = RFTDB_Connect(); eval{ my $sql = "select sysdate from dual"; my $sth = ($hDB->prepare($sql) or die "ERROR DB Access" . $DBI::errstr ); $sth->execute() or die "ERROR DB Access" . $sth->errstr ; $recs = ($sth->fetchall_arrayref or die "ERROR DB Access" . $sth->errstr ); my ($i,$j); foreach $i (0...$#$recs){ foreach $j (0...$#{$recs->[$i]}){ print "$recs->[$i][$j]\t"; } print "\n"; } $sth->finish; RFTDB_Disconnect(); print "SQL excute OK:\n$sql\n"; }; if($@){ print "ERROR: $@\n"; RFTDB_Disconnect(); exit(1); } }