简体   繁体   English

在 @INC 中找不到 DBD/Oracle.pm

[英]Can't locate DBD/Oracle.pm in @INC

I'm trying to connect to Oracle via DBI, but can't make it work.我正在尝试通过 DBI 连接到 Oracle,但无法正常工作。

My setup:我的设置:

# cat /proc/version 
Linux version 2.6.18-194.el5 (mockbuild@ca-build10.us.oracle.com) (gcc version 4.1.2 20080704 (Red Hat 4.1.2-48)) #1 SMP Mon Mar 29 20:06:41 EDT 2010
# uname -i 
i386
# perl -v 
This is perl, v5.8.8 built for i386-linux-thread-multi 
<...>
# echo $ORACLE_HOME
/usr/lib/oracle/12.1/client

I'm trying to connect using this script:我正在尝试使用此脚本进行连接:

#!/usr/bin/perl
# dbi.pl
use warnings;
use strict;
use DBI;

$ENV{ORACLE_HOME}="/usr/lib/oracle/12.1";
$ENV{LD_LIBRARY_PATH}="/usr/lib/oracle/12.1/client/lib";
$ENV{NLS_LANG}="american_america.CL8MSWIN1251";

my $user='user';
my $pw='pw';
my $host='servername';
my $port='1521';
my $SID = 'SID';
my $source = "dbi:Oracle:$host;sid=$SID;port=$port";

my $dbh=DBI->connect($source,$user,$pw,{PrintError=>0,AutoCommit=>0,RaiseError=>1}) or die "Oracle:$DBI::errstr\n";

And when I'm trying to execute it I'm getting an error:当我尝试执行它时,我收到了一个错误:

#  ./dbi.pl
install_driver(Oracle) failed: Can't locate DBD/Oracle.pm in @INC (@INC contains: /usr/lib/perl5/site_perl/5.8.8/i386-linux-thread-multi /usr/lib/perl5/site_perl/5.8.8 /usr/lib/perl5/site_perl /usr/lib/perl5/vendor_perl/5.8.8/i386-linux-thread-multi /usr/lib/perl5/vendor_perl/5.8.8 /usr/lib/perl5/vendor_perl /usr/lib/perl5/5.8.8/i386-linux-thread-multi /usr/lib/perl5/5.8.8 .) at (eval 3) line 3.
Perhaps the DBD::Oracle perl module hasn't been fully installed,
or perhaps the capitalisation of 'Oracle' isn't right.
Available drivers: DBM, ExampleP, File, Proxy, Sponge, mysql.
 at ./dbi.pl line 21

I tried to reinstall DBD-Oracle:我试图重新安装 DBD-Oracle:

root@hostname:/tmp/DBD-Oracle-1.66# perl Makefile.PL
Using DBI 1.52 (for perl 5.008008 on i386-linux-thread-multi) installed in /usr/lib/perl5/vendor_perl/5.8.8/i386-linux-thread-multi/auto/DBI/

Configuring DBD::Oracle for perl 5.008008 on linux (i386-linux-thread-multi)

Remember to actually *READ* the README file! Especially if you have any problems.

Installing on a linux, Ver#2.6
Using Oracle in /usr/lib/oracle/12.1/client
DEFINE _SQLPLUS_RELEASE = "1201000100" (CHAR)
Oracle version 12.1.0.1 (12.1)

        Unable to locate an oracle.mk or other suitable *.mk
        file in your Oracle installation.  (I looked in
        /usr/lib/oracle/12.1/client/rdbms/demo/demo_xe.mk /usr/lib/oracle/12.1/client/rdbms/demo/demo_rdbms32.mk /usr/lib/oracle/12.1/client/rdbms/demo/demo_rdbms.mk /usr/lib/oracle/12.1/client/rdbms/lib/ins_rdbms.mk /usr/share/oracle/12.1/client/demo.mk under /usr/lib/oracle/12.1/client)

        The oracle.mk (or demo_rdbms.mk) file is part of the Oracle
        RDBMS product.  You need to build DBD::Oracle on a
        system which has one of these Oracle components installed.
        (Other *.mk files such as the env_*.mk files will not work.)
        Alternatively you can use Oracle Instant Client.

        In the unlikely event that a suitable *.mk file is installed
        somewhere non-standard you can specify where it is using the -m option:
                perl Makefile.PL -m /path/to/your.mk

        See the appropriate README file for your OS for more information and some alternatives.

     at Makefile.PL line 1187.
root@hostname:/tmp/DBD-Oracle-1.66#  ls /usr/lib/oracle/12.1/client/
total 8.0K
drwxr-xr-x 2 root root 4.0K Sep 24 13:23 bin/
drwxr-xr-x 2 root root 4.0K Sep 24 13:23 lib/
root@hostname:/tmp/DBD-Oracle-1.66#  

So, I don't have this 'rdbms' directory, because I installed instantclient.所以,我没有这个'rdbms'目录,因为我安装了instantclient。 Is there any way to make it work without installing a database?有什么方法可以在不安装数据库的情况下使其工作?

Recent full oracle database installs don't install all the bits you need for DBD::Oracle.最近完整的 oracle 数据库安装并未安装 DBD::Oracle 所需的所有位。 I'm sorry but I cannot remember the name of the optional bit you need to install.很抱歉,我不记得您需要安装的可选位的名称。 However, an alternative (and a much easier one) is to download Oracle instant client "basic", "sdk" and "sqlplus", unzip them somewhere and point your LD_LIBRARY_PATH at that.但是,另一种选择(也是更简单的一种)是下载 Oracle 即时客户端“basic”、“sdk”和“sqlplus”,将它们解压缩到某个位置,然后将 LD_LIBRARY_PATH 指向那里。 It also makes you independent of the current Oracle database install which means if your dba upgrades it (or part of it) you don't need to think about rebuilding DBD::Oracle.它还使您独立于当前的 Oracle 数据库安装,这意味着如果您的 dba 升级它(或其中的一部分),您无需考虑重建 DBD::Oracle。

BTW, setting your LD_LIBRARY_PATH in your perl script won't work - it is too late.顺便说一句,在你的 perl 脚本中设置你的 LD_LIBRARY_PATH 是行不通的——太晚了。

in my case this solved the problem:就我而言,这解决了问题:

     perl -MCPAN -e shell
      get DBD::Oracle
      quit

     cd ~/.cpan/build/DBD-Oracle***
     export LD_LIBRARY_PATH=/usr/lib/oracle/11.2/client64/lib
     export ORACLE_HOME=/usr/lib/oracle/11.2/client64/
     perl Makefile.PL
     make
        make install

使用: sudo cpan -i DBD::Oracle 解决

Hi did you set LD_LIBRARY_PATH ?嗨,你设置了LD_LIBRARY_PATH吗? According to the docs , Makefile.PL should work with instant client now, but this is the only option I see that you have not followed (or at least shown that you have followed).根据文档,Makefile.PL 现在应该与即时客户端一起使用,但这是我看到您没有遵循的唯一选项(或至少表明您已经遵循)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM