Database Reference
In-Depth Information
UNIX Environment
Many UNIX systems already have a Perl installation. Usually, the DBI module for database
access is missing in that installation and it would require a C compiler to install it. Much easier
is setting some environment variables for using Perl in an
ORACLE_HOME
by following the steps
described next.
PATH
First of all, the executable search path variable
PATH
needs to be modified, such that
$ORACLE_HOME/
perl/bin
is searched before any directory that contains the Perl interpreter shipped with the
operating system.
$ export PATH=$ORACLE_HOME/perl/bin:$PATH
$ which perl
/opt/oracle/product/db10.2/perl/bin/perl
PERL5LIB
The second step is setting the Perl module search path. Perl programs normally have extension
.pl
, while Perl modules have extension
.pm
. The DBI is implemented by a file named
DBI.pm
. It
is this file that the Perl interpreter needs to locate. Fortunately, this variable does not depend
on the word size of the platform or the version of Perl. The following setting may be used
generically:
export PERL5LIB=$ORACLE_HOME/perl/lib:$ORACLE_HOME/perl/lib/site_perl
On a 32-bit Linux system, the required file is
$ORACLE_HOME/perl/lib/site_perl/5.8.3/
i686-linux- thread-multi/DBI.pm
. Perl locates the file by also searching subdirectories of the
directories specified with
PERL5LIB
. It starts looking in the most specific directory for the build
and version of Perl, then tries directories further up in the directory tree and finally stops by
searching the directory specified.
In the above example, the version of Perl (
perl
-version
) is 5.8.3 and the build is i686-
linux-thread-multi (Intel x86 32-bit machine architecture with Perl multithreading linked in).
In case
PERL5LIB
is set incorrectly or the DBI is not present in the Perl installation (such as the
one that ships with the operating system), you will get an error similar to the following:
$ echo $PERL5LIB
/opt/oracle/product/db10.2/perl/lib
$ echo "use DBI;" | perl
Can't locate DBI.pm in @INC (@INC contains: /opt/oracle/product/db10.2/perl/lib/5.8.
3/ i686-linux-thread-multi /opt/oracle/product/db10.2/perl/lib/5.8.3 /opt/oracle/pro
duct/ db10.2/perl/lib) at dbi.pl line 3.
BEGIN failed--compilation aborted at dbi.pl line 3.
In the preceding example,
$ORACLE_HOME/perl/lib/site_perl
is missing from
PERL5LIB
.
The fix is to add this directory to
PERL5LIB
. Use a colon as the separator character when setting
up multiple directories for searching. If you need to use additional Perl modules not located in
$ORACLE_HOME/perl/lib
or even wrote your own modules (it's not that hard, trust me), you must
also add their locations to
PERL5LIB
. The source code depot contains a Perl module, which is built
on top of the DBI.