1.安装instantclient的相关包:
instantclient-basic-linux-x86-64-11.2.0.2.0.zip 基础包
instantclient-sdk-linux-x86-64-11.2.0.2.0.zip 使用c或perl连接db
instantclient-sqlplus-linux-x86-64-11.2.0.2.0.zip sqlplus
2.设置环境变量
export PATH=/home/loganalysis/perlM/instantclient/instantclient_11_2:$PATH
export ORACLE_HOME=/home/loganalysis/perlM/instantclient/instantclient_11_2
export LD_LIBRARY_PATH=/home/loganalysis/perlM/instantclient/instantclient_11_2
export SQLPATH=/home/loganalysis/perlM/instantclient/instantclient_11_2:${SQLPATH}
export TNS_ADMIN=/home/loganalysis/perlM/instantclient/instantclient_11_2:${TNS_ADMIN}
3.复制tnsnames.ora至/home/loganalysis/perlM/instantclient/instantclient_11_2
开始测试。
#!/usr/bin/perl
use DBI;
$dbname="bossdata";
$user="system";
$passwd="javama";
$dbh="";
$dbh = DBI->connect("dbi:Oracle:$dbname",$user,$passwd) or die "can't connect to database ";
$sth=$dbh->prepare("select * from user_tables");
$sth->execute;
while (@recs=$sth->fetchrow_array) {
print $recs[0].":".$recs[1]."\n";
}
$dbh->disconnect;
print "hello \n";
//测试通过。