Oct 20 2011
The Mac OS X version is 10.6.8.
The Perl is installed at /usr/bin/perl, version (perl -version) is "v5.10.0 built for darwin-thread-multi-2level."
There are two good articles on the web that discuss this issue, but none of them is perfect for me. So I tried to add my stuff here.
The first is about installing sqlplus: http://www.danilovizzarro.it/2008/07/how-to-install-sqlplus-and-the-oracle-client-v102-on-a-mac-os-x-leopard-1054/
The second is about installing DBD::Oracle: http://blacka.com/david/2008/11/12/how-to-install-dbdoracle-on-mac-os-x/
To install sqlplus, you need download instantclient form oracle site, the following (64-bit) packages:
To install DBD::Oracle, you need one more package:
Once you download and unzip them, all the files will go to a directory called instantclient_10_2. Move this folder to something like /opt/oracle
$ sudo mv instantclient_10_2 /opt/oracle
You should set unix environment variable like the following:
To connect to the an Oracle via sqlplus you can run the following command:
# sqlplus DB_USER/DB_PASS@//DB_HOST:DB_PORT/DB_SID
To install DBD::Oracle, you will need to download perl DBD package from CPAN, I chose version 1.32.
After you download the package, unzip it to ~/Download/DBD-Oracle-1.32, make sure you have set ORACLE_HOME and DYLD_LIBRARY_PATH correctly.
You need to set some soft link in $ORACLE_HOME (This is the key step most readme files failed to mention.)
$ cd /opt/oracle/instantclient_10_2/
$ sudo ln -s /opt/oracle/instantclient_10_2/ lib
$ sudo ln -s libclntsh.dylib.10.1 libclntsh.dylib
$ ls -l
lrwxr-xr-x 1 root admin 31 Oct 19 16:36 lib -> /opt/oracle/instantclient_10_2/
lrwxr-xr-x 1 root admin 20 Oct 19 16:32 libclntsh.dylib -> libclntsh.dylib.10.1
Now you can compile the DBD::Oracle Package now:
$ cd ~/Download/DBD-Oracle-1.32
$ perl Makefile.PL
$ sudo make install
In perl script you connect to oracle server using the following code:
#! /usr/bin/perl -w
my $sid = "host=host.xyz.com;sid=DBSID;port=1521"
my $dbh = DBI->connect("dbi:Oracle:$sid", $user, $pass) or die "ERROR: failed to connect db: $@\n";