0

I have to insert blob in oracle view. In ths case there is no opportunity to use this EMPTY_BLOB() with returning clause. Like this: "Insert into table (a,b,c) values (a,b, EMPTY_BLOB()) RETURNING c into :photo" Becouse RETURING doesnt work in views I need a method to create empty blob before inserting data, but i dont know how to do it with PDO.

Thanks!

1
  • have you tried inserting into the underlying tables? Commented Jun 13, 2012 at 12:39

1 Answer 1

1

In PHP connected to ORA DB I have recently solved a problem with inserting of CLOB which should be treated the same way.

In my case it was enough to insert the data as characters while when binding I set the length of characters as length of bind. But You can try to use a function TO_BLOB(), that needs an input casted to a RAW:

INSERT INTO my_blob_table (my_blob_column) VALUES (TO_BLOB(UTL_RAW.CAST_TO_RAW('some binary data as string')))

or also a universal TO_LOB() should work (converts to CLOB or BLOB depending on source/target column):

INSERT INTO my_blob_table (my_blob_column) VALUES (TO_LOB('some binary data as string'))

EDIT: Using google I found these should work:

  • if we have a long column that we want to convert to clob/blob:
create table t1 (id int, my_blob blob);
create table t2 (id int, my_long long);
insert into t2 values (1, rpad('*',4000,'*'));
insert into t1 select id, to_lob(my_long) from t2;
  • if we have a long raw column that we want to convert to blob:
create table t1 (id int, my_blob blob);
create table t2 (id int, my_long_raw long raw);
insert into t2 values (1, rpad('*',4000,'*'));
insert into t1 select id, to_blob(my_long_raw) from t2;

That should work... See here and here.

Sign up to request clarification or add additional context in comments.

5 Comments

Seems that i could`t use your sollution. Becouse my column is long, so I can bind only PDO::PARAM_LOB data type to be inserted there, but long data connot be converted with cast_to_raw :(
Then try the same without casting. If You have LONG type of data then there should be no problem with casting of LONG to BLOB using TO_BLOB nor TO_LOB.
strange, but it doesn`t work too. I have error: ORA-01461: can bind a LONG value only for insert into a LONG column
Hmm and why can't You convert the LONG column into a BLOB column? LONG is kinda outdated... Or at least convert Your LONG to LONG RAW and then call TO_BLOB(your_long_raw_data). Cannot think of better way...
@Maxim I added some examples that should work. Notice the difference between to_lob and to_blob...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.