使用php pdo在oracle中插入blob

时间:2012-06-13 10:17:38

标签: php oracle pdo oracle11g

我必须在oracle视图中插入blob。在这种情况下,没有机会将此EMPTY_BLOB()与return子句一起使用。像这样: “插入表格(a,b,c)中的值(a,b,EMPTY_BLOB())将c返回到:照片” 回归并不知道如何用PDO做到这一点。

谢谢!

1 个答案:

答案 0 :(得分: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'))

编辑:使用谷歌,我发现这些应该可行:

  • 如果我们要将long列转换为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;
  • 如果我们要将long raw列转换为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;

这应该有用......请参阅herehere

相关问题