Re: manipulating blobs in sqlplus



JillS wrote:
I am working for a software dev company doing a port to Oracle (from
SQL Server). Currently, when deploying the initial software (or
changes to the software) the database changes are made using sql
scripts. DML handles changes to the data. This issue is that the
software comes with preloaded documents (blobs). In SQL Server, they
generate the DML scipts - for example inserts would be like this
select 'insert into tab1 values (' || colA || ',' || colB || ')' from
tab1;
In SQL Server, this works for blobs. The value of the blob is spit out
as a stream of hex, which the insert statement can interpret when run
at the client side. There is also no size limit on the blob field
(unlike the 32767 byte limit for lobs in Oracle).

In Oracle, sqlplus just won't display a blob to the screen (which
actually makes sense since it is binary data). But this means I can't
duplicate the funtionality. I have tried generating the insert
statement with utl_raw.cast_to varchar2 and then inserting with
utl_raw.cast_to_raw, but this doesn't work (I have cut and paste
below).

So far they are against delivering the actual documents to the client
site outside of the database and have a script load them in. Other
than this, I can only think of creating a temporary table with the
table_name, column_name and blob value and then inserting with null
values and using pl/sql to update and load the blobs.

Am I overlooking a simpler solution?

Here is what I have tried:
jill@RHORC> get insert_word_doc.sql
1 create table demo
2 ( id int primary key,
3 theClob blob,
4 theBlob blob
5 )
6 /
7 create or replace
8 procedure load_a_file( p_id in number,
9 p_filename in varchar2 )
10 as
11 l_blob blob;
12 l_bfile bfile;
13 begin
14 insert into demo (id, theBlob) values ( p_id, empty_blob() )
15 returning theBlob into l_blob;
16 l_bfile := bfilename( 'JSALO_DIR', p_filename );
17 dbms_lob.fileopen( l_bfile );
18 dbms_lob.loadfromfile( l_blob, l_bfile,
19 dbms_lob.getlength( l_bfile ) );
20 dbms_lob.fileclose( l_bfile );
21 end;
22 /
23* exec load_a_file( 1, 'testword.doc' );
24
jill@RHORC> @insert_word_doc.sql

Table created.


Procedure created.


PL/SQL procedure successfully completed.

jill@RHORC> select theblob from demo;
SP2-0678: Column or attribute type can not be displayed by SQL*Plus

jill@RHORC> select 'insert into demo (id, theblob) values ('||id||','||
chr(39)||theblob||chr(39)||'));' from demo;
select 'insert into demo (id, theblob) values ('||id||','||chr(39)||
theblob||chr(39)||'));' from demo
*
ERROR at line 1:
ORA-00932: inconsistent datatypes: expected NUMBER got BLOB

jill@RHORC> get gen_ins.sql
1 set termout off
2 set feedback off
3 set pages 0
4 spool out.sql
5 select 'insert into demo values ('||id||','||
null||',utl_raw.cast_to_raw('||chr(39)||
6 utl_raw.cast_to_varchar2(dbms_lob.substr(theblob,2000,1))
7 ||chr(39)||'));' from demo;
8* spool off
9
jill@RHORC> @gen_ins.sql
jill@RHORC> set termout on
jill@RHORC> set feedback on
jill@RHORC> !more out.sql
insert into demo values (1,,utl_raw.cast_to_raw('?Ia!?a
?y 0 2 ?yyy / yy
yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy
yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy
yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy
yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyiYA #` ?? L
bjbj!! . L
yy yy
yy ? ? ? ? ? ? ? ?
U U U U ^L ? ^L
' ? ? ? ? ? ? ? ? ? | ?
? ? ? ? ? $ Y h E t
I ? ? ? ?
? ? I ? ? ? ?
a i i i ? ? ? ?
? ? |
i ?
| i i V n
@ ? ?
2 ? o ^L P?+??eC U ? "
? ^L | ? 0 ' ? x ? ? ( ? 2
2 0 ? ? b D ? ?
i ? ? ?
? ? I I a
? ? ?
' ? ? ? ? ? ?
D ?
? ? ? ? ? ? yyyy
^L '));



jill@RHORC> @out
string """ missing terminating quote (").
ERROR:
ORA-01756: quoted string not properly terminated

Thanks.


Prior to 11g, you could not see the BLOB values in SQL*Plus...which as you say, does make some sense. If the BLOB is a .wav file, how does a ..wav file "look" in a text-based utility? I have read, but haven't confirmed it yet, that 11g does let you see the BLOB values in SQL*Plus.

Anyway...when I had to move BLOBs from SQL Server to Oracle, I used a pass-through program. The first thing I did was to move all of the table's columns, except for the BLOB column(s). Then, I used DTS to update the Oracle table with the BLOB column value read from SQL Server, using the Primary Key of the table to determine the row to update.

You can also write code using something like Perl DBI to interface with the two databases. Read one row's BLOB value and PK column from the source table. Update the destination table with the BLOB value. Repeat for each row.

HTH,
Brian



--
===================================================================

Brian Peasland
dba@xxxxxxxxxxxxxxxxxxx
http://www.peasland.net

Remove the "nospam." from the email address to email me.


"I can give it to you cheap, quick, and good.
Now pick two out of the three" - Unknown

--
Posted via a free Usenet account from http://www.teranews.com

.



Relevant Pages

  • RE: How to make your SQL Server database grow exponentially with linear data
    ... > We have this database that we use to collect 1000's of rows of data a day. ... > SQL Server reports no free space. ... turns out the problem are with the blob fields. ... > and inserted a new row we probably would have been able to shrink the ...
    (microsoft.public.sqlserver.server)
  • How to make your SQL Server database grow exponentially with linear data
    ... We have this database that we use to collect 1000's of rows of data a day. ... SQL Server reports no free space. ... turns out the problem are with the blob fields. ... of a bigger blob, but they are much lower on the exponential curve than the ...
    (microsoft.public.sqlserver.server)
  • Re: How to make your SQL Server database grow exponentially with linear data
    ... Turns out it's a bug in SQL Server, ... database, which means there was only about 17gb of actual data in the ... separate data file, so when it gets out of control again we can just move ... turns out the problem are with the blob fields. ...
    (microsoft.public.sqlserver.server)
  • Re: Store File in SQLServer via ADO
    ... "William Vaughn" wrote: ... > with a convoluted file structure. ... > BLOB to a local temp file which slows the process even further. ... Does one need a SQL Server license to get to it? ...
    (microsoft.public.data.ado)
  • Re: Blobs and SQL Server
    ... Older versions of SQL Server required the blob be loaded in chunks, ... There is a cpu and disk IO hit while inserting the blob. ... Director of Text Mining and Database Strategy ... If a large file is inserted, then it will require many small chunks. ...
    (microsoft.public.sqlserver.fulltext)