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

I'm trying to fetch CLOB data from an Oracle database using perl but it gives me ORA-03115 error. I am able to extract non-CLOB data from teh same table without any problems. I m not sure why this is happening. Any ideas to resolves this problem???. Thanks,

Replies are listed 'Best First'.
Re: Selecting Clob data from Oracle
by Itatsumaki (Friar) on Nov 23, 2003 at 18:33 UTC

    This has come up several times on the DBI users mailing list: for example, here, here, here, here, and here.

    Those posts go into more details, but there are several things you can try: ensure LongReadLen is set, upgrade to the most recent version of DBD::Oracle, and ensure your DBD::Oracle has been compiled against Oracle client libs more recent than 7i.

    -Tats
Re: Selecting Clob data from Oracle
by Roger (Parson) on Nov 23, 2003 at 22:25 UTC
    I have extracted a CLOB reading portion from one of my CGI scripts. I guess it's more helpful to list an example here. :-)

    In the example below, I try to retrieve binary image stored as CLOB in the database, and display the image in the Web browser.

    #!/usr/local/bin/perl -w # Paper stock preview CGI use strict; use DBI; use DBD::Oracle qw(:ora_types); use CGI; # Set oracle home environment $ENV{ORACLE_HOME}='/home/oracle/OraHome1'; # Connect as Oracle my $dbh=DBI->connect("dbi:Oracle:tnsentry","user","passwd"); # Use CGI my $q = new CGI; my $stock_id = $q->param('stock_id'); # get paper stock id # Find the url and image size from another table my $sth = $dbh->prepare("select stock_url, stock_imagesize from stock +where stock_id=?"); $sth->execute($stock_id); my @res=$sth->fetchrow_array(); $sth->finish; if ($res[0] eq 'CLOB') { # stock image is stored directly inside the database $dbh->{LongReadLen}=$res[1]; # set up the CLOB retrieval size my $sth=$dbh->prepare("select stock_mimetype, stock_image from stock + where stock_id=?"); $sth->execute($stock_id); my @res=$sth->fetchrow_array(); print "Content-Type: $res[0]\n\n"; # display the image print "$res[1]"; # in web browser $sth->finish; } else { # stock image stored externally # ... } $dbh->disconnect();