2012-06-13 52 views
0

我必须在oracle视图中插入blob。在这种情况下,没有机会使用带有返回子句的EMPTY_BLOB()。像这样: “插入表(a,b,c)的值(a,b,EMPTY_BLOB())返回c到:photo” Becouse RETURING doesn t work in views I need a method to create empty blob before inserting data, but i don t知道如何使用PDO。在oracle中使用php插入blob pdo

谢谢!

+0

你试过插入基础表吗? – tbone

回答

1

在连接到ORA DB的PHP中,我最近解决了插入CLOB的问题,它应该以相同的方式处理。

在我的情况下,它足以将数据作为字符插入,而在绑定时,我将字符的长度设置为绑定的长度。但你可以尝试使用功能TO_BLOB(),需要浇铸为RAW输入:

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

或者也可以是通用的TO_LOB()应该工作(转换为CLOBBLOB根据源/目标列):

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

编辑:使用谷歌,我发现这应该工作:

  • 如果我们有,我们要转换为clob/blob一个long柱:
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; 
  • 如果我们有,我们要转换为blob一个long raw柱:
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; 

那应该工作...见herehere

+0

似乎我不能使用你的溶剂。因为我的专栏很长,所以我可以只绑定PDO :: PARAM_LOB数据类型,但是长数据不能用cast_to_raw转换:( – Maxim

+0

然后在没有转换的情况下尝试相同的方法。如果您有'LONG'类型的数据,那么使用'TO_BLOB'和'TO_LOB'将'LONG'强制转换为'BLOB'应该没有问题。 – shadyyx

+0

奇怪,但它不起作用。我有错误:ORA-01461:只能绑定一个LONG值插入到LONG列 – Maxim