Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: Selecting Clob data from Oracle

by Roger (Parson)
on Nov 23, 2003 at 22:25 UTC ( [id://309372]=note: print w/replies, xml ) Need Help??


in reply to Selecting Clob data from Oracle

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();

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://309372]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (7)
As of 2024-04-19 08:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found