Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/68.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql 读取oracle表中的BLOB列_Sql_Oracle_Plsql_Blob - Fatal编程技术网

Sql 读取oracle表中的BLOB列

Sql 读取oracle表中的BLOB列,sql,oracle,plsql,blob,Sql,Oracle,Plsql,Blob,我有一个表tbl,它有以下列: create table tbl (id number, colA BLOB, ColB BLOB, Insert_time timestamp(0) ) 当我运行下面的查询时,它工作正常: select id, substr(substr(utl_raw.cast_to_varchar2( dbms_lob.subst

我有一个表tbl,它有以下列:

create table tbl (id number,
                  colA BLOB,
                  ColB BLOB,
                  Insert_time timestamp(0)
                  )
当我运行下面的查询时,它工作正常:

select id,
substr(substr(utl_raw.cast_to_varchar2( dbms_lob.substr( utl_compress.lz_uncompress(tbl.colA), 2000, 1) ),instr(utl_raw.cast_to_varchar2( dbms_lob.substr( utl_compress.lz_uncompress(tbl.ColA), 2000, 1) ),'MeterReadingReasonCode',1),25),24,2) first
--substr(substr(utl_raw.cast_to_varchar2( dbms_lob.substr( utl_compress.lz_uncompress(tbl.ColB), 2000, 1) ),instr(utl_raw.cast_to_varchar2( dbms_lob.substr( utl_compress.lz_uncompress(tbl.ColB), 2000, 1) ),'MeterReadingTypeCode',1),23),22,2) second
from tbl 
where
tbl.INSERT_TIME >=  To_Date('04-01-2020 12:00:00 AM' ,'dd-mm-yyyy hh12:mi:ss AM')
and tbl.INSERT_TIME <=  To_Date('04-08-2020 11:00:00 PM' ,'dd-mm-yyyy hh12:mi:ss AM')
这意味着(例外情况表明)列
ColLB
中不包含用于解压缩的有效值

测试表明,is很可能是一个带有
NULL
值的列-请参见下面的脚本

create table tbl (ColB BLOB);
                  
insert into tbl ( colb)
values(null);

select  
   utl_compress.lz_uncompress(tbl.ColB)
from tbl  
;

ORA-29261: bad argument
ORA-06512: at "SYS.UTL_SYS_COMPRESS", line 56
ORA-06512: at "SYS.UTL_SYS_COMPRESS", line 226
ORA-06512: at "SYS.UTL_COMPRESS", line 89
请注意,如果存储的非
NULL
值已损坏(即不是压缩格式),则会看到不同的异常

insert into tbl ( colb)
values(HEXTORAW('cafe'));

select  
   utl_compress.lz_uncompress(tbl.ColB)
from tbl  
;

ORA-29294: A data error occurred during compression or uncompression.
ORA-06512: at "SYS.UTL_SYS_COMPRESS", line 56
ORA-06512: at "SYS.UTL_SYS_COMPRESS", line 226
ORA-06512: at "SYS.UTL_COMPRESS", line 89
因此,作为一种解决方法,您应该使用
大小写
station测试
NULL

select 
  case when colB is not NULL then 
    substr(substr(utl_raw.cast_to_varchar2( dbms_lob.substr( utl_compress.lz_uncompress(tbl.ColB), 2000, 1) ),instr(utl_raw.cast_to_varchar2( dbms_lob.substr( utl_compress.lz_uncompress(tbl.ColB), 2000, 1) ),'MeterReadingTypeCode',1),23),22,2) 
  end as  second
from tbl 

嗨,Marmite,谢谢你的意见。是的,你是对的。另一个BLOB列可为null,因此引发了错误。我已经按照你的建议处理了。@PujaShaw,你很好!
insert into tbl ( colb)
values(HEXTORAW('cafe'));

select  
   utl_compress.lz_uncompress(tbl.ColB)
from tbl  
;

ORA-29294: A data error occurred during compression or uncompression.
ORA-06512: at "SYS.UTL_SYS_COMPRESS", line 56
ORA-06512: at "SYS.UTL_SYS_COMPRESS", line 226
ORA-06512: at "SYS.UTL_COMPRESS", line 89
select 
  case when colB is not NULL then 
    substr(substr(utl_raw.cast_to_varchar2( dbms_lob.substr( utl_compress.lz_uncompress(tbl.ColB), 2000, 1) ),instr(utl_raw.cast_to_varchar2( dbms_lob.substr( utl_compress.lz_uncompress(tbl.ColB), 2000, 1) ),'MeterReadingTypeCode',1),23),22,2) 
  end as  second
from tbl