【问题标题】:Extract BLOB with length greater than 4000 in Oracle SQL在Oracle SQL中提取长度大于4000的BLOB
【发布时间】:2019-10-03 10:03:54
【问题描述】:

我正在尝试使用以下查询提取 BLOB 变量。

select utl_raw.cast_to_varchar2(BLOB_VAR) from Dual

但是我遇到了一个错误。

ORA-22835: Buffer too small for CLOB to CHAR or BLOB to RAW conversion (actual: 4060, maximum: 2000)

如果可以提取大于 4000 个字符的 BLOB 值,请让我们看看,因为 varchar2 的限制是 4000。

我尝试使用 concat 选项

select concat(concat(utl_raw.cast_to_varchar2(dbms_lob.substr(BYTES_,2000,1)),utl_raw.cast_to_varchar2(dbms_lob.substr(BYTES_,2000,2001))),utl_raw.cast_to_varchar2(dbms_lob.substr(BYTES_,2000,4001)))from ACT

但我得到了这个错误

01489. 00000 -  result of string concatenation is too long```

Is there any way to get a longer string value?

【问题讨论】:

标签: oracle plsql blob concat varchar2


【解决方案1】:

您可以尝试创建函数,而不是过程。示例(摘自link

create or replace function F(B BLOB) 
return clob is 
  c clob;
  n number;
begin 
  if (b is null) then 
    return null;
  end if;
  if (length(b)=0) then
    return empty_clob(); 
  end if;
  dbms_lob.createtemporary(c,true);
  n:=1;
  while (n+32767<=length(b)) loop
    dbms_lob.writeappend(c,32767,utl_raw.cast_to_varchar2(dbms_lob.substr(b,32767,n)));
    n:=n+32767;
  end loop;
  dbms_lob.writeappend(c,length(b)-n+1,utl_raw.cast_to_varchar2(dbms_lob.substr(b,length(b)-n+1,n)));
  return c;
end;
/

然后在您需要的任何查询中使用该函数。

【讨论】:

  • 对不起,我也不能使用函数。
  • 如果你复制粘贴别人的代码,你也应该添加指向资源的链接。
  • 我总是这样。我当时很急。我会搜索链接并放上去!
  • @vijay kumar,你确定你不能使用函数吗?在您尝试解决时,您写道:select utl_raw.cast_to_varchar2(BLOB_VAR) from Dual。 cast_to_varchar2 这是一个函数。如果您创建自己的函数,您将拥有your_function_name,而不是cast_to_varchar2
  • @F.Lazarescu 我只能使用内置函数,无法创建新函数
【解决方案2】:

我找到了一种使用 to_clob 函数获取输出的简单方法

select to_clob(BYTES_) from ACT

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-02-02
    • 2020-03-20
    • 1970-01-01
    • 2014-08-24
    • 2017-12-25
    • 2011-04-12
    • 1970-01-01
    • 2021-02-28
    相关资源
    最近更新 更多