Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.server -> Re: LONG RAW TO BLOB

Re: LONG RAW TO BLOB

From: Thomas Kyte <tkyte_at_us.oracle.com>
Date: Tue, 04 Aug 1998 15:29:47 GMT
Message-ID: <35d1235d.94473726@192.86.155.100>


A copy of this was sent to Patrick Tan <ptan_at_mindspring.com> (if that email address didn't require changing) On Mon, 03 Aug 1998 09:15:43 -0400, you wrote:

> need examples of conversion of data from LONG RAW to BLOB in PL/SQL.
>i.e. READ column of
>LONG RAW type and write it to column of BLOB type. Thanks.
>
>
>
>Patrick Tan

You cannot in pl/sql. You can convert a LONG to a CLOB (dbms_sql gives you piecewise access to a long but not a long raw in pl/sql -- you can read 32k of LONG and write 32k of CLOB and since LOBs support piecewise read/write, you can copy the whole thing in pl/sql).

If you are interested, I have a small C program called "unload". You compile this (its in OCI) and give it a query like:

$ ./unload scott/tiger "select LONG_RAW_COLUMN, FILENAME_COLUMN from T where..."

and it will read each row in T and create a file named after the FILENAME_COLUMN and put the contents of the LONG_RAW_COLUMN into that file (so if you have 5 rows in T, you'll get 5 files).

You can then use a procedure such as:

create or replace directory MY_FILES as '/export/home/tkyte/public_html';

declare

    l_bfile bfile;
    l_blob blob;
begin

    insert into blobs values ( 'MyGif', empty_blob() )     return theBlob into l_blob;

    l_bfile := bfilename( 'MY_FILES', 'aria.gif' );     dbms_lob.loadfromfile( l_blob, l_bfile, dbms_lob.getlength(l_bfile) );     commit;
end;
/

to load the files into the database -- dbms_lob.loadfromfile will read the binary file in for you.

If you are interested in getting the SOURCE code for unload (makefiles for NT and Unix), see http://govt.us.oracle.com/~oracle/owarepl/doc/dnld.html  

Thomas Kyte
tkyte_at_us.oracle.com
Oracle Government
Herndon VA  

http://govt.us.oracle.com/ -- downloadable utilities  



Opinions are mine and do not necessarily reflect those of Oracle Corporation  

Anti-Anti Spam Msg: if you want an answer emailed to you, you have to make it easy to get email to you. Any bounced email will be treated the same way i treat SPAM-- I delete it. Received on Tue Aug 04 1998 - 10:29:47 CDT

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US