Linux下安装Perl Oracle模块
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
1、下载DBI和DBD
/~timb/DBI-1.605/ DBI-1.605
在/~pythian/DBD-Oracle-1.21/下载DBD-Oracle-1.21
2、查看perl是否安装
[oracle@olivenan ~]$ perl -v
This is perl, v5.8.5 built for i386-linux-thread-multi
Copyright 1987-2004, Larry Wall
Perl may be copied only under the terms of either the Artistic License or the
GNU General Public License, which may be found in the Perl 5 source kit.
Complete documentation for Perl, including FAQ lists, should be found on
this system using `man perl' or `perldoc perl'. If you have access to the
Internet, point your browser at /, the Perl Home Page.
[oracle@olivenan ~]
3、安装DBI,应该先安装DBI否则DBD无法安装成功
解压过程略
[root@olivenan DBI-1.605]# perl Makefile.PL
....
[root@olivenan DBI-1.605]# make
...
[root@olivenan DBI-1.605]# make install
...
4、安装DBD-Oracle
[root@olivenan ~]# tar -zxvf DBD-Oracle-1.21.tar.gz
我在root下进行安装出现错误如下:提示未设置环境变量ORACLE_HOME
[root@olivenan DBD-Oracle-1.21]# perl Makefile.PL
Using DBI 1.605 (for perl 5.008005 on i386-linux-thread-multi) installed in /usr/lib/perl5/site_perl/5.8.5/i386-linux-thread-multi/auto/DBI/
Configuring DBD::Oracle for perl 5.008005 on linux (i386-linux-thread-multi)
Remember to actually *READ* the README file! Especially if you have any problems.
Trying to find an ORACLE_HOME
Your LD_LIBRARY_PATH env var is set to ''
The ORACLE_HOME environment variable is not set and I couldn't guess it.
It must be set to hold the path to an Oracle installation directory
on this machine (or a machine with a compatible architecture).
See the appropriate README file for your OS for more information.
ABORTED!
[root@olivenan DBD-Oracle-1.21]# export ORACLE_HOME=/u01/app/oracle/product/10.2.0/db_1
[root@olivenan DBD-Oracle-1.21]# perl Makefile.PL
...
[root@olivenan DBD-Oracle-1.21]# make
...
[root@olivenan DBD-Oracle-1.21]# make install
...
至此安装成功
5、验证结果
脚步如下:
db.pl :
#!/usr/bin/perl -w
use DBI;
#$dbh = DBI->connect("dbi:Oracle:$dbname",$user,$passwd) or die "can't connect todat
abase ". DBI-errstr;
# Connect to target DB
my $dbh = DBI->connect("dbi:Oracle:orcl","test","test", {'RaiseError' => 1});
# Insert one row
my $rows = $dbh->do("INSERT INTO t (id) VALUES (1)");
#print "insert $rows rows\n";
# query
my $sth = $dbh->prepare("SELECT id FROM t");
$sth->execute;
while(my @ref = $sth->fetchrow_array ) {
print "$ref[0]\n";
}
$dbh->disconnect();
"db.pl" 25L, 501C written
在root下执行脚本出错
[root@olivenan ~]# perl db.pl
install_driver(Oracle) faile
d: Can't load '/usr/lib/perl5/site_perl/5.8.5/i386-linux-thread-multi/auto/DBD/Oracle/Oracle.so' for module DBD::Oracle: libclntsh.so.10.1: cannot open shared object file
: No such file or directory at /usr/lib/perl5/5.8.5/i386-linux-thread-multi/DynaLoader.pm line 230.
at (eval 3) line 3
Compilation failed in require at (eval 3) line 3.
Perhaps a required shared library or dll isn't installed where expected
at db.pl line 12
[root@olivenan ~]# chmod oracle:oinstall db.pl
[root@olivenan ~]# mv db.pl /home/oracle/
oracle用户下执行,成功
[oracle@olivenan ~]$ perl db.pl
1
[oracle@olivenan ~]$ perl db.pl
1
1
[oracle@olivenan ~]$ perl db.pl
1
1
1
[oracle@olivenan ~]$