Use the Oracle 11g version of Perl to connect to databases in AIX

I just got my connection from AIX into Oracle through Perl working, using DBD::Oracle. This is good news because it opens up the potential to do processing in our robust shared AIX environment on an LPAR licensed as an Oracle client, not a server. Instead of embedding stuff into Oracle’s extended SQL language just to get it to run on the server, we could now simply write in Perl. This could end up saving us quite a bit of money on Oracle licensing.

The configuration may seem trivial, but I ran into so many gotchas on this, that I just hacked into some Oracle scripts and essentially picked up their environment to run. It was compiled with an @INC path that didn’t exist, so I just created it and moved in all of their compiled Perl. It’s Perl 5.8.3 compiled in single thread mode which is different from the Perl that is compiled with Base AIX.

First, find your perl library wherever Oracle ended up putting it and move it to the location hardcoded in @INC:

(find where the Oracle lib directory is)
tar -cvf /tmp/oraperl.tar lib
mkdir -p /ade/aime_perl_build_latest/perl58/bin/AIX64
cd /ade/aime_perl_build_latest/perl58/bin/AIX64
tar -xvf /tmp/oraperl.tar

Next, find and copy the actual perl executable into /ade/aime_perl_build_latest/perl58/bin/AIX64.

I pick this path, simply because it is what @INC is hardcoded to for me:

# echo "print @INC" | ./perl

Next, I just made a simple test script:


use DBI qw(:sql_types);

my $dbh;
my $address = "
                                (HOST= yourhostnamehere)
my $mode = 0;

$dbh= DBI->connect('dbi:Oracle:', "username@".$address , "password",
                {ora_session_mode => $mode})
                or die "Could not connect\n";

print "Connect failed \n" unless $dbh;
$dbh->{RowCacheSize} = 100;

my $sth = $dbh->prepare("select * from tab",{ora_check_sql => 0 });
$sth->execute or die "\nError: Sql failed: \n";

my $returned="";
while (my @row = $sth->fetchrow_array)
                $returned = $row[0];
                print (" $row[0]\n");

$dbh->disconnect or die ("disconnect failed", $DBI::err);

That’s all there is to it, this connects and works just fine. You can probably do something similar at 10g, but don’t try with 9i, it looks like a pretty old version of Perl.

Having now conquered Perl, php is next on my wishlist:

PHP Development Center at Oracle
pecl oci8

Leave a Reply

Your email address will not be published. Required fields are marked *