kgnickl has asked for the wisdom of the Perl Monks concerning the following question:

I've tried to get DBI::Oracle working, but gave up. Version of Perl is ActivePerl 5.8.8 Build 122. Downgrading is not an option. I need something that will work and can be easily installed/setup on a Windows XP 32 bit computer and a Windows 2008 Server 2008 64 bit. Connection on Windows XP will be a Oracle XE DB (10g) and in Windows Server 2008 it will be an Oracle 11g DB. I was trying to use what I'm familiar w/ which is would be my $dbh = DBI->connect("dbi:Oracle:host=" . $host . ":" . $port . ";sid=" . $sid, $user, $passwd); I'm open to using DBI ODBC, but I'm not sure what I would have to do since the connection parameters are different. The DB is remote and I know the host, port, sid, username, and password. Is there anothe perl module or method for Oracle DB connection? I'm used to Java where its pretty simple (grab a oracle file and throw it in the project and add a few lines and your good to go. Any ideas? Or code examples to get me going with ODBC?

Replies are listed 'Best First'.
Re: Perl Module for Oracle DB Connection?
by kennethk (Abbot) on Mar 30, 2011 at 15:49 UTC
    Are you sure you mean DBI::Oracle, or do you mean DBI and DBD::Oracle? I am writing this on a Windows XP 32-bit machine running ActivePerl 5.8.9 and have been using DBD::Oracle seamlessly for years to connect to our Oracle 10g DB. As you are using ActiveState, did you attempt to install the package using PPM? How do you know it wasn't working? Your connector should look something like:

    my $db_name = 'host=db.url.com;port=1521;sid=user'; my $db_user = 'userid'; my $db_pass = 'passwd'; my @dbi_path = ("dbi:Oracle:$db_name",$db_user,$db_pass); my $oracle = DBI->connect( @dbi_path, { PrintError => 0, RaiseError => 0, AutoCommit => 0, } ) or die "Database connect to $db_name failed:" . $DBI::errstr;
Re: Perl Module for Oracle DB Connection?
by marto (Cardinal) on Mar 30, 2011 at 15:49 UTC

    Perhaps if you tell us what went wrong when you tried to get DBD::Oracle (since DBI::Oracle doesn't exist) working we'd be able to offer advice. As mentioned in the README there are various platform/architecture specific documents you should be reading.

    Update: Perl 5.8.8 is from 2006, you may wish to consider upgrading.

Re: Perl Module for Oracle DB Connection?
by runrig (Abbot) on Mar 30, 2011 at 16:18 UTC
    I don't have a tnsnames.ora file on my windows box, so the connect syntax I use is:
    DBI->connect("dbi:Oracle:$host:$port/$service_name", $user, $password, + {RaiseError => 1});
    ActiveState comes with DBI and DBD::Oracle these days, so I'll assume it's not a library installation problem (unless you have an old build of ActiveState perl). Also, you don't mention the error you're getting...so what is it?
Re: Perl Module for Oracle DB Connection?
by cavac (Prior) on Mar 30, 2011 at 17:16 UTC

    DBD::Oracle in this ancient ActivePerl version is actually quite broken and has it's share of problems with newer Oracle server versions (including random crashes when using it for long sessions). If been struggling with all kinds of odd behavior for years, now. When i upgraded to ActivePerl 5.12 and also installed the latest Oracle client, all (most) of the problems just vanished.

    Can you connect to tha database using sqlplus? Does tnsping work? It's hard to give you more than generic advice without more information.

    On a side note (my personal opinion): Always treat DBD::ODBC as a last-ditch attempt when there are better suited packages available. ODBC is very generic, most database specific optimization technics wont work, your software will be slow and you will hog quite a lot of resources on the database server if you are unlucky. Please don't make your database admin break into tears...

      most database specific optimization technics wont work, your software will be slow and you will hog quite a lot of resources on the database server if you are unlucky

      Although I'd not argue that using the DBD specific to your database is probably the way to go if you only need to access that database what evidence do you have to back up this statement?

        Yes and no. For my latest projects with PostgreSQL i measured a speed difference of 2-5% in my evaluation tests.

        This page here also claims some speed difference for Oracle.

        If (and how much) speed difference you will experience will depend on the amount of data as well as the complexity of the database.

        Never ever try to use DBD::ODBC on a Unify database, where the performance will indeed drop to speeds where granma in here wheelchair will take over with ease. That is because Unify never ever has put time and/or effort into updating their braindead ODBC drivers. They are so 1995.


        Enjoy, Have FUN! H.Merijn
Re: Perl Module for Oracle DB Connection?
by fidesachates (Monk) on Mar 30, 2011 at 16:19 UTC
    Thinking outside the box, I've had problems too with the modules for connecting to oracles and to get around it, I executed external commands to sqlplus and just parsed through the output to get my data. It's a hacky work around sure, but it gets the job done. Of course getting the module to work is the best course of action. I'm merely providing a quick fix here.
Re: Perl Module for Oracle DB Connection?
by afoken (Chancellor) on Mar 31, 2011 at 09:45 UTC

    Hints:

    • ActivePerl 5.8.8 is ancient code. Consider switching to a recent Strawberry Perl. Strawberry Perl comes with a complete set of compiler, linker and make (dmake), so you can install modules from CPAN out-of-the-box, like you would do on any unix system.
    • The current DBD::Oracle 1.28 has some problems, it needs two tiny patches (1, 2) to compile and run cleanly. Additionally, the test t/26exe_array.t fails when Test::NoWarnings is installed, this problem can safely be ignored.
    • Nearly all DBD::* modules need some kind of database client library to compile, and DBD::Oracle is no exception. You need at least the OCI packages, available on the Oracle setup CD / DVD. Many people report success with a recent version of Oracle Instant Client. See also the documentation of DBD::Oracle for details.
    • Ask on the dbi-users mailing list if you have problems with DBI.
    • Last time I tested, DBD::ODBC was way slower than DBD::Oracle, due to the extra overhead of the ODBC manager and the ODBC driver, so I can not recommend to use DBD::ODBC to connect to Oracle. To make things even worse, Windows comes with a really ancient Oracle ODBC driver that causes a lot of trouble. You really need to update it with a recent version of Oracles own ODBC driver if you want to use DBD::ODBC to connect to Oracle.

    Alexander

    --
    Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)