【问题标题】:Inserting blob in oracle using php pdo使用 php pdo 在 oracle 中插入 blob
【发布时间】:2012-06-13 10:17:37
【问题描述】:

我必须在 oracle 视图中插入 blob。在这种情况下,没有机会将此 EMPTY_BLOB() 与返回子句一起使用。像这样: “插入表(a,b,c)值(a,b,EMPTY_BLOB())将c返回:photo” 因为 RETURING 不知道t work in views I need a method to create empty blob before inserting data, but i dont 知道如何使用 PDO。

谢谢!

【问题讨论】:

  • 你试过插入基础表吗?

标签: php oracle pdo oracle11g


【解决方案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

【讨论】:

  • 看来我无法使用您的解决方案。因为我的列很长,所以我只能绑定要插入其中的 PDO::PARAM_LOB 数据类型,但不能使用 cast_to_raw 转换长数据:(
  • 然后在不强制转换的情况下尝试相同的操作。如果您有LONG 类型的数据,那么使用TO_BLOBTO_LOBLONG 转换为BLOB 应该没有问题。
  • 奇怪,但它也不起作用。我有错误:ORA-01461:只能绑定 LONG 值以插入 LONG 列
  • 嗯,为什么不能将 LONG 列转换为 BLOB 列? LONG 有点过时了......或者至少将您的LONG 转换为LONG RAW,然后致电TO_BLOB(your_long_raw_data)。想不出更好的办法...
  • @Maxim 我添加了一些应该可以使用的示例。注意to_lobto_blob 之间的区别...
猜你喜欢
  • 2016-11-13
  • 2017-03-23
  • 2015-04-29
  • 2014-05-06
  • 2013-08-20
  • 2011-06-21
  • 1970-01-01
  • 2011-05-04
  • 2019-11-06
相关资源
最近更新 更多