一生醉生忘死,就让他继续下去吧!
分类: Oracle
2013-10-30 10:50:57
1、在
然后下载以下安装包(使用的是10g的客户端,最新的为11g的):
Oracle-instantclient-basic-10.2.0.5-1.i386.rpm
oracle-instantclient-devel-10.2.0.5-1.i386.rpm
oracle-instantclient-jdbc-10.2.0.5-1.i386.rpm
oracle-instantclient-sqlplus-10.2.0.5-1.i386.rpm
2、debian不能直接安装rpm包,需要使用alien
运行 apt-get install alien libaio
sudo alien --scripts *.rpm
dpkg -i *.deb
3、在 /etc/ld.so.conf 文件最后,加入一行:
/usr/lib/oracle/10.2.0.5/client/lib
然后执行 ldconfig 使配置生效。
(执行 sqlplus 来验证配置。)
4、在 /etc/profile 文件最后,加入:
export ORACLE_HOME=/usr/lib/oracle/xx.x/client
export PATH=$PATH:$ORACLE_HOME/bin
export LD_LIBRARY_PATH=$ORACLE_HOME/lib
然后执行source /etc/profile 使配置生效。
(执行 echo $ORACLE_HOME 来验证配置。)
5、在cpan上下载DBD::Oracle,编译安装
cd
perl make*.PL
make
make install
执行代码:
#!/usr/bin/perl
use strict;
use warnings;
use DBI;
my $db_host = "192.168.6.201";
my $db_port = "1521";
my $db_sid = "bill";
my $db_user = "scott";
my $db_pass = "tiger";
my $database = "dbi:Oracle://$db_host:$db_port/$db_sid";
my $dbh = DBI->connect( $database,$db_user,$db_pass ) or die "Can't connect to database";
my $sql = 'select count(*) from EMP';
my $sth = $dbh->prepare( $sql );
$sth->execute;
my $count = $sth->fetchrow_array;
$sth->finish();
print "The table EMP have [$count] rows.\n";
$dbh->disconnect;
print "Perl connect Oracle is OK!\n";