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

I have a pdf being stored in an Oracle table as a BLOB.

I was able to insert the data file but when reading it out perl treats it weird. I store the data as a value in a hash, and when I dump (Data::Dumper) the hash I see all the binary data associated with its key. This is fine. However when I try to directly use the value, such as passing it as a parameter to length() or print() or even Dumper(), it shows up as undefined.

I thought this was exceedingly odd, considering we have other apps doing this very thing that seem to work and I am unable to find any discrepancies. I also tried to write the data to a file both using regular perl code and directly using FileHandle, both treated the data as undefined.

Anyone out there have experience with this?

Replies are listed 'Best First'.
Re: Ora_blob being treated as undefined?
by paulbort (Hermit) on Sep 10, 2004 at 19:15 UTC
    Could there be some subtle difference in the keys? Does it work if you put it in a foreach my $key ( keys %pdfs)?

    Is there an extra layer of hashing you glossed over in the Data::Dumper output? (I know it's a rude question, but I've done it...)

    Can other apps get the data out and read it correctly? You might be able to test this by piping the output from the command-line query parser (with some creative flags) into your PDF viewer.

    --
    Spring: Forces, Coiled Again!
Re: Ora_blob being treated as undefined?
by Lhamo Latso (Scribe) on Sep 10, 2004 at 17:40 UTC

    This is an Oracle question. Is it a BLOB or a BFILE? Normally, Oracle stores BLOBs inline (in the column, in the row of the datafile). When you store the .pdf on the filesystem, the table column only stores the LOB locator, not the actual binary data. To access the filesystem for a BFILE, you build a LOB locator by putting together the directory name plus the filename. (the directory part is the alias from the Oracle "create or replace directory" command)

    Your error may be that you are reading a LOB locator and thinking it is a .pdf ??

    Please specify more, and maybe I can answer more specifically.

      I'm no Oracle whiz, but according to TOAD it's being stored in a BLOB. I actually have no idea what a BFILE is :( (I don't get access to all the fun db stuff).

      When I dump the hash I can see the pdf headers in the binary so I'm thinking it's coming out right... kinda.