1.617.682.4508

Pythian Blog

The world discusses #Pythian on Twitter. Have a question? Use our hashtag and ask away.

Emergency

24x7 Support

Not a Pythian client but need help now? No problem. Click here.

Are you aware of an existing DBA opening or consulting requirement in your organization? Enter your email for a chance to win one year's access to Safari Books.

  

Install DBD::Oracle on 64-bit Linux and Oracle 11g

By: John Scoles

Karun Dutt and I managed to get DBD::Oracle 1.21 to install on a 64-bit Linux OS against the Oracle 11 full client. Here’s what we did.

As root, we downloaded DBD::Oracle from CPAN.

# perl -MCPAN -eshell
cpan> get DBD::Oracle
...

We replaced the distribution makefile with: http://svn.perl.org/modules/dbd-oracle/trunk/Makefile.PL (this is the latest Makefile.PL).

# cd /root/.cpan/build/DBD-Oracle-1.21
# export ORACLE_HOME=<actual value of Oracle Home>
# export ORACLE_SID=<actual value of ORACLE_SID>
# export ORACLE_USERID=<a working ORACLE_USERID>
# export LD_LIBRARY_PATH=$ORACLE_HOME/lib:$ORACLE_HOME
# perl Makefile.PL
...
# make
...
# make test
...
# make install
...

It works!

10 Responses

  1. Laks says:

    Hi,
    Does the latest DBD::Oracle have features like batching and Oracle types support features similar to the jdbc thin driver provided by oracle.

    thanks and Regards

  2. John Scoles says:

    not sure what exactly you mean by batching and Oracle type support.

    Do you have any examples?

  3. Laks says:

    Thanks for your response.
    1) I am referring to the facility provided by oracle jdbc thin driver to batch the insert/update operations so that roundtrips to the server is reduced.
    eg: One could set the batch parameter on the connection or on a specific statement object/handle to a value say 10. Then irrespective of the # of calls to execute a update/insert on the statement handle, every 10 update/insert requests get batched and sent to DB server to execute. This reduces the round trips to server which normally happens for every insert/update that gets sent to server to execute each time on execute call.
    I am not aware how this works in DBD::Oracle.
    2) How can one retrieve pl/sql Table type or bind such things with DBD::Oracle.
    JPublisher provided by oracle maps between oracle types and jdbc types easily.

    Thanks and regards

  4. John Scoles says:

    For #1 I think you are refering to the OCI Array_interface and yes DBD::Oracle supports it (since 1.18)
    check out this link
    http://search.cpan.org/~timb/DBI-1.604/DBI.pm#bind_param_array

    As for #2 I think we support is as well check out these links
    http://search.cpan.org/~pythian/DBD-Oracle-1.21/Oracle.pm#Returning_A_Recordset
    http://search.cpan.org/~pythian/DBD-Oracle-1.21/Oracle.pm#Binding_Cursors

  5. Laks says:

    Thanks John for your responses.
    1) I had a look at the bind_param_array and execute_array interfaces added from 1.18 of DBD::Oracle.
    Though it helps in array binding and helps it is not equivalent to the batching facility in java driver.With jdbc one can transparently batch inserts and updates to be sent to rdbms server in one shot. inserts and updates are done normally but driver internally batches them together like one unit of work.
    Anyway i am happy that the array interface helps in binding array of values for inserts from 1.18.

  6. Sergey says:

    Thank you very much for patching Makefile.PL!
    It’s very easy now to install DBD::Oracle with 11g.

  7. John Scoles says:

    Laks Said

    ‘Though it helps in array binding and helps it is not equivalent to the batching facility in java driver.’

    Hi Laks I was curious about this so I had a look under the hood of the JDBC interface and which calls it was using in OCI to accomplish the task.

    Well to my surprise both JDBC and DBD::Oracle use almost the exactly the same code under the hood so I think it is a case of ‘We do it this way any you do it the wrong way’:);).

    In JDBC you
    1) prepare a statement (con.prepareStatement)
    2) bind values to the statement (stmt.setString(2, “bla”))
    3) add the statement to a batch (stmt.addBatch())
    4) repeat 2-3 above and then
    5) execute your batch. (stmt.executeBatch())

    in DBD:Oracle
    1) prepare the statement ($dbh->prepare)
    2) bind all the values to the statement ($sth->bind_param_array)
    3) execute the statement. ($sth->execute_array)

    In both JDBC and DBD::Oracle only 1 round trip call to the execute is made in OCI.

    So me thinks it is a case here of ‘You say ‘potato’ and I say ‘potato’.

    cheers

  8. Paul Vallee says:

    John,
    I think Laks is saying ‘potato’ and you’re saying “pineapple”.
    The array interface is only for batching re-use of one handle for multiple uses, saving round trips. The batch interface lets you batch multiple statements, including different ones, into one database call.
    No?
    Paul

  9. John Scoles says:

    Actully ‘No’ is correct.

    The JDBC interface does let you ‘batch’ multiple statments with one execute but this is just hiding the fact that one execute is fired for ecach of them.

    From the JDBC docs

    “The batch update facility is used with a PreparedStatement to associate multiple sets of input parameter values with a single PreparedStatement object.”

    so this

    PreparedStatement stmt = con.prepareStatement(
    “INSERT INTO employees VALUES (?, ?)”);

    stmt.setInt(1, 2000);
    stmt.setString(2, “Kelly Kaufmann”);
    stmt.addBatch();

    stmt.setInt(1, 3000);
    stmt.setString(2, “Bill Barnes”);
    stmt.addBatch();

    // submit the batch for execution
    int[] updateCounts = stmt.executeBatch();

    will do 1 OCIExecute .

    but this

    Statement stmt = con.createStatement();
    stmt.addBatch(”INSERT INTO employees VALUES (1000, ?,?)”);
    stmt.setInt(1, 2000);
    stmt.setString(2, “Kelly Kaufmann”);
    stmt.addBatch(”INSERT INTO departments VALUES (?, ?’)”);
    stmt.setInt(1, 260);
    stmt.setString(2, “Shoe”);
    stmt.addBatch(”INSERT INTO emp_dept VALUES (?, ?)”);
    stmt.setInt(1, 1000);
    stmt.setInt(2, 260);

    int[] updateCounts = stmt.executeBatch();

    will do 3 OCIExecute command one for each SQL. So in this case there are 3 round trips to the server rather than just one for the last example.

  10. Paul Vallee says:

    Excellent info, John, thanks.
    Paul

Leave a Reply

Start NowWith Pythian - database design, management and emergency handling capabilities...

Pythian Blog

Connecting to Oracle with SQL Server 2005 x64
The quirks of connecting to Oracle from SQL 2005 64
more



Live Updates

pythian: Join us for a webinar June 4: Migrating to an Open Source DB Platform. Paul Vallee speaking. Register at
more



RSSTestimonials

  • Casey Dyke

    Database Team Manager Service Delivery and Applications , Telstra

    Pythian were recently engaged to take a lead role in a high end infrastructure build project at Telstra. Our requirements were a combination of... more