Documente Academic
Documente Profesional
Documente Cultură
Page 1 of 7
Questions
Home > Question Details
Resources
Archives
Links
Popular
Hot
Files
Firas -- Thanks for the question regarding "Long Raw to BLOB", version 8.1.7
Submitted on 22-Oct-2003 19:01 Central time zone Last updated 5-Apr-2010 10:23 Tom's latest followup | Bookmark | Bottom
You Asked
Hi Tom, We are using an Oracle 8.1.7 database. Is there a way in PL/SQL or Java Stored Procedure to convert a Long Raw into a BLOB? Thanks, Firas Khasawneh
and we said...
ops$tkyte@ORA817DEV> create table gtt ( id int, x blob ); Table created. ops$tkyte@ORA817DEV> ops$tkyte@ORA817DEV> create table t ( id int primary key, x long raw ); Table created. ops$tkyte@ORA817DEV> ops$tkyte@ORA817DEV> insert into t values( 1, rpad( 'a', 2000, 'a' ) ); 1 row created. ops$tkyte@ORA817DEV> ops$tkyte@ORA817DEV> ops$tkyte@ORA817DEV> declare 2 l_id number := 1; 3 l_blob blob; 4 begin 5 execute immediate ' 6 insert into gtt 7 select :x, to_lob(x) 8 from t 9 where id = :x' using l_id, l_id; 10 11 select x into l_blob from gtt where id = l_id; 12 end; 13 / PL/SQL procedure successfully completed. if you just want to convert single row for a session. use
create table new_table as select ...., to_lob(long_raw) from old_table to permanently convert all rows.
Reviews Excellent, Thanks October 23, 2003 - 3pm Central time zone Reviewer: Firas from NC USA Hi Tom, Thanks a lot for your prompt response. Is it possible to update a Long Raw column with a BLOB value? I read some where that that is possible by converting the binary bytes into hex but I am not sure if that is possible or how to do it. Any suggestions is highly appreciated. Bookmark | Bottom | Top
http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:132138854...
12/3/2012
Page 2 of 7
April 19, 2005 - 9am Central time zone Reviewer: A reader Hi Tom, I have tables x and y as create table x ( id number, str varchar2(255), lrimage long_raw ); create table y ( id number, str varchar2(255), blimage blob );
Table x has about 11 million rows and I am trying to move data from table x to table y. I tried the following: create or replace procedure procblob as tstr varchar2(255); timage blob; begin .......... select str, to_lob(lrimage) into tstr, timage from x where id = 1; insert into y values (1, tstr, timage); ..... end; / When I try to compile this procedure I am getting the error PL/SQL: ORA-00932: inconsistent datatypes: expected - got BINARY I also tried create or replace procedure procblob as tstr varchar2(255); timage long raw; begin .......... select str, lrimage into tstr, timage from x where id = 1; insert into y values (1, tstr, to_lob(timage)); ..... end; / Again I am getting the same error. Please let me know what to do. Thanks.
insert into y select str, to_lob(lrimage) from x where ...; no plsql, just sql.
http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:132138854...
12/3/2012
Page 3 of 7
Does it work in 9.2.0.6 too? May 2, 2006 - 7am Central time zone Reviewer: Roland Rottlaender from Germany Hi Tom, is there a difference for 9.2.0.6.? I have a table blobdata( ownerid longid segmentid segment ) But a Query Select longid, to_lob(segment) from blobdata where longid = 12345 returns ORA-00932: inconsistent datatypes: expected - got BINARY
Then I create table blobdata_temp( ownerid NUMBER(10), longid NUMBER(10), segmentid NUMBER(10), segment BLOB ) and tried INSERT INTO blobdata_temp SELECT ownerid, longid, segmentid, to_lob(segment) from blobdata where ... All I got is ORA-00997: illegal use of LONG datatype I really has no idea what's going wrong... Would be great if you could help me... Thanks, Roland
http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:132138854...
12/3/2012
Page 4 of 7
ops$tkyte@ORA9IR2> ops$tkyte@ORA9IR2> create table blobdata_temp( 2 ownerid NUMBER(10), 3 longid NUMBER(10), 4 segmentid NUMBER(10), 5 segment BLOB 6 ); Table created. ops$tkyte@ORA9IR2> ops$tkyte@ORA9IR2> INSERT INTO blobdata_temp 2 SELECT ownerid, longid, segmentid, to_lob(segment) 3 from blobdata; 2 rows created. ops$tkyte@ORA9IR2> ops$tkyte@ORA9IR2> select dbms_lob.getlength( segment) from blobdata_temp; DBMS_LOB.GETLENGTH(SEGMENT) --------------------------2000 16383 ops$tkyte@ORA9IR2>
September 4, 2008 - 10am Central time zone Reviewer: Visi from Albania
Hi Tom, I have been visiting your site so many times, but it is only this time I am taking the chance to make a question regarding the convertion of Long Raw to BLOB. I am in the process of loading some 40(GB)pictures from a MSSQL system to Oracle 10g R2 using OLEDB though heterogeneus system(HS). This is my target table in oracle: create table T_PICTURES ( IMAGE_ID VARCHAR2(10) not null, FILENAME VARCHAR2(250), ACTIONNR NUMBER, PICTURE BLOB, BYTES VARCHAR2(10), INFO VARCHAR2(10), IMAGEDATE DATE ); alter table T_PICTURES add constraint XPK_PICTURES primary key (IMAGE_ID)); And this is the description from sqlplus of the remote table in MSSQL. image_id varchar2(8) filename varchar2(250) actionnr number(10) y picture long raw y bytes number(10) y info number(10) y imagedate date y
The following is a code I wrote and it is suposed to migrate a record at a time, any time it is being executed and converting the LONG RAW picture field to BLOB using the TO_LOB function. begin for c in (select from where and and loop
insert into t_pictures (image_id, filename, actionnr, picture, bytes, info, imagedate) SELECT "ImageID" image_id, "FileName" filename, "ActionNr" actionnr, to_lob("Picture") picture, "Bytes" bytes, "Info" info, "ImageDate" imagedate
http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:132138854...
12/3/2012
Page 5 of 7
FROM ITCPortrait@mssql WHERE "ImageID" = c.appno; commit; end loop; -end; When I try to run it, I am getting ORA-00997: illegal use of LONG datatype ORA-06512: at line 10 Am I doing something wrong here? I am realy confused. I'd really appreciate your intervention on this. I hope I was somehow clear in my explanations. Thanks and regards, Visi
http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:132138854...
12/3/2012
Page 6 of 7
Note: The LOOP might look unnecessary there but probably I am going to increase the number of records loaded in a single run. Thanks again Tom Regards, Visi
Hi Tom, The avarege size of a picture is about 10KB.The largest foto so far looks to be around 20KB. Probably I was lucky :) Thanks for letting me know. Regards, Visi
Long raw March 6, 2009 - 3am Central time zone Reviewer: Anis from Dhaka, Bangladesh
Would you help me, I want to insert doc or pdf file into oracle database from oracle developer 6i. Thanks Anis
and this worked. But when I tried to execute only select to_lob(text) from user_views;
I got the below error SQL Error: ORA-00932: inconsistent datatypes: expected - got LONG 00932. 00000 - "inconsistent datatypes: expected %s got %s"
Could you please help me understand the reason for this behaviour. Thanks in advance Badri
The lob needs to "live" somewhere, with just a select - the lob wouldn't exist in a table anywhere. The to_lob function was implemented purely to convert a long to a lob - once (as a migration device). That was the intended functionality.
http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:132138854...
12/3/2012
Page 7 of 7
Can you explain to us the difference between BLOB and RAW datatype and for what kind of data you use RAW data type.
That would work - if the descrlong is not to be in the list of distincted columns. If it is, you will not be using SQL only to do this.
Write a Review
All information and materials provided here are provided "as-is"; Oracle disclaims all express and implied warranties, including, the implied warranties of merchantability or fitness for a particular use. Oracle shall not be liable for any damages, including, direct, indirect, incidental, special or consequential damages for loss of profits, revenue, data or data use, incurred by you or any third party in connection with the use of this information or these materials.
http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:132138854...
12/3/2012