> 数据库 > Oracle >

perl连接远程oracle

 #!/usr/bin/perl -w

use DBI;

my $dbSid = "test";
my $dbHost = "testhost";
my $dbUser = "user";
my $dbPassword = "password";
my $dbh = DBI->connect("DBI:Oracle:host=$dbHost:$dbSid", $dbUser, $dbPassword) or print ($DBI::errstr);
my $sth = $dbh->prepare("select * from table");
$sth->execute;
my @recs = "";
while ( my @recs=$sth->fetchrow_array) {
print $recs[0].":".$recs[1].":".$recs[2]."/n";
}
$dbh->finish;

$dbh->disconnect;

exit if(1);

#perl test.pl

install_driver(Oracle) failed: Can't locate DBD/Oracle.pm in @INC (@INC contains: /usr/lib64/perl5/site_perl/5.8.8/x86_64-linux-thread-multi /usr/lib64/perl5/site_perl/5.8.7/x86_64-linux-thread-multi /usr/lib64/perl5/site_perl/5.8.6/x86_64-linux-thread-multi /usr/lib64/perl5/site_perl/5.8.5/x86_64-linux-thread-multi /usr/lib/perl5/site_perl/5.8.8 /usr/lib/perl5/site_perl/5.8.7 /usr/lib/perl5/site_perl/5.8.6 /usr/lib/perl5/site_perl/5.8.5 /usr/lib/perl5/site_perl /usr/lib64/perl5/vendor_perl/5.8.8/x86_64-linux-thread-multi /usr/lib64/perl5/vendor_perl/5.8.7/x86_64-linux-thread-multi /usr/lib64/perl5/vendor_perl/5.8.6/x86_64-linux-thread-multi /usr/lib64/perl5/vendor_perl/5.8.5/x86_64-linux-thread-multi /usr/lib/perl5/vendor_perl/5.8.8 /usr/lib/perl5/vendor_perl/5.8.7 /usr/lib/perl5/vendor_perl/5.8.6 /usr/lib/perl5/vendor_perl/5.8.5 /usr/lib/perl5/vendor_perl /usr/lib64/perl5/5.8.8/x86_64-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 test.pl line 10



oracle clientoracle instant clientoraclerpm32bit64bit
Instant Client downloads for Linux x86

DBD-Oracleperl dbi

DBD-Oracle,

DBD-OracleCPANperl

perl test.pl



-----------------------------------------------------------------------------------------

RPM

oracle-instantclient-sqlplus

oracle-instantclient-jdbc

oracle-instantclient-basic

oracle-instantclient-devel


export LD_LIBRARY_PATH=/usr/lib/oracle/10.2.0.4/client/lib/:${LD_LIBRARY_PATH}
export TNS_ADMIN=/usr/lib/oracle/10.2.0.4/admin
export ORACLE_HOME=/usr/lib/oracle/10.2.0.4/client/
PATH=$PATH:$ORACLE_HOME/bin

 DBD-ORACLE

    # perl Makefile.PL  -m /usr/share/oracle/10.2.0.4/client/demo.mk
    # make
    # make install

"-m",  

        Unable to locate an oracle.mk, proc.mk or other suitable *.mk
        file in your Oracle installation.  (I looked in
        /usr/lib/oracle/10.2.0.4/client/rdbms/demo/demo_xe.mk /usr/lib/oracle/10.2.0.4/client/rdbms/lib/oracle.mk /usr/lib/oracle/10.2.0.4/client/rdbms/demo/oracle.mk /usr/lib/oracle/10.2.0.4/client/rdbms/demo/demo_rdbms.mk /usr/lib/oracle/10.2.0.4/client/precomp/demo/proc/proc.mk /usr/lib/oracle/10.2.0.4/client/precomp/demo/proc/demo_proc.mk /usr/lib/oracle/10.2.0.4/client/proc/lib/proc.mk /usr/lib/oracle/10.2.0.4/client/proc16/lib/proc16.mk under /usr/lib/oracle/10.2.0.4/client)

        The oracle.mk (or demo_rdbms.mk) file is part of the Oracle
        RDBMS product. The proc.mk (or demo_proc.mk) file is part of
        the Oracle Pro*C 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 1076.



make

/usr/bin/ld: skipping incompatible /usr/lib/oracle/10.2.0.4/client/lib/libocci.so when searching for -locci
/usr/bin/ld: cannot find -locci
collect2: ld returned 1 exit status
make: *** [blib/arch/auto/DBD/Oracle/Oracle.so] Error 1 

 libocci

#ldd /usr/lib/oracle/10.2.0.4/client/lib/libocci.so

        linux-gate.so.1 =>  (0xffffe000)
        libstdc++.so.5 => not found
        libm.so.6 => /lib/libm.so.6 (0xf7ecf000)
        libgcc_s.so.1 => /lib/libgcc_s.so.1 (0xf7ec3000)
        libc.so.6 => /lib/libc.so.6 (0xf7d83000)
        /lib/ld-linux.so.2 (0x56555000)

 libstdc++.so.5 

#find /usr/lib -name "libstdc++*"

/usr/lib/libstdc++.so.6
/usr/lib/libstdc++.so.6.0.8
/usr/lib/gcc/x86_64-redhat-linux/4.1.1/libstdc++.a
/usr/lib/gcc/x86_64-redhat-linux/4.1.1/libstdc++.so
/usr/lib/gcc/x86_64-redhat-linux/4.1.1/32/libstdc++.a
/usr/lib/gcc/x86_64-redhat-linux/4.1.1/32/libstdc++.so
/usr/lib64/libstdc++.so.6
/usr/lib64/libstdc++.so.6.0.8

#ln -s /usr/lib/libstdc++.so.6 /usr/lib/libstdc++.so.5


apache 2008-07-24
nfs 2008-07-24


LinuxID 2009-07-17
perl 2008-09-11
perl dbi fetch 2008-08-11
perl  2008-08-07
Perl 2008-08-06



(责任编辑:IT)