Database Reference
In-Depth Information
Perl will not be able to load the ORACLE driver module DBD::Oracle unless the correct
variable is used and the correct search path is set. The most concise test consists of running the
following command:
$ echo "use DBI;use DBD::Oracle" | perl
Can't load '/opt/oracle/product/db10.2/perl/lib/site_perl/5.8.3/i686-linux-thread-mu
lti/auto/DBD/Oracle/Oracle.so' for module DBD::Oracle: libclntsh.so.10.1: cannot ope
n shared object file: No such file or directory at /opt/oracle/product/db10.2/perl/l
ib/ 5.8.3/i686-linux-thread-multi/DynaLoader.pm line 229.
at - line 1
Compilation failed in require at - line 1.
BEGIN failed--compilation aborted at - line 1.
If you get an error such as this, you need to fix the shared library search path. Error messages
differ slightly per platform, but always mention that libclntsh.so could not be found.
The following Perl DBI program called perl-dbi-test.pl is ideal for testing connectivity
to an ORACLE instance. It prompts for user name, password, and Net service name, and then
attempts to connect to the DBMS. If it succeeds, it selects the database login user name and
prints it to the screen.
#!/usr/bin/env perl
# RCS: $Header: /home/ndebes/it/perl/RCS/perl-dbi-test.pl,v 1.1 2007/01/26 16:07:13
ndebes Exp ndebes $
# Perl DBI/DBD::Oracle Example
use strict;
use DBI;
print "Username: \n";
my $user = <STDIN>;
chomp $user;
print "Password: \n";
my $passwd = <STDIN>;
chomp $passwd;
print "Net Service Name (optional, if ORACLE instance runs locally and ORACLE_SID is
set): \n";
my $net_service_name = <STDIN>; # Oracle Net service name from tnsnames.ora or other
name resolution method
chomp $net_service_name;
if ($net_service_name) {
print "Trying to connect to $user/$passwd\@$net_service_name\n";
}
else {
print "Trying to connect to $user/$passwd\n";
}
Search WWH ::




Custom Search