我有这样的BLOB数据:
{.\.r.t.f.1.\.d.e.f.f.0.T.a.b.l.o.S.i.m.p.l.e...
我需要使用 Tablo 分隔符将其分为2列:
{.\.r.t.f.1.\.d.e.f.f.0.
S.i.m.p.l.e...
分隔符十六进制代码
2A002A007400610062006C006F002A002A00 --> **Tablo**
Blob数据长度大于10000,最大数据3162910。
我尝试用十六进制代码,blob_to_clob转换等尝试dbms_lob.substr,dbms_lob.instr,但我做不到。
我该怎么做?
答案 0 :(得分:1)
您需要先将BLOB转换为CLOB,然后才能将CLOB视为字符串。
create or replace function blob_to_char (p1_blob BLOB)
return clob is
out_clob clob;
n number;
begin
if (p1_blob is null) then
return null;
end if;
if (length(p1_blob)=0) then
return empty_clob();
end if;
dbms_lob.createtemporary(out_clob,true);
n:=1;
while (n+32767<=length(p1_blob)) loop
dbms_lob.writeappend(out_clob,32767,utl_raw.cast_to_varchar2(dbms_lob.substr(p1_blob,32767,n)));
n:=n+32767;
end loop;
dbms_lob.writeappend(out_clob,length(p1_blob)-n+1,utl_raw.cast_to_varchar2(dbms_lob.substr(p1_blob,length(p1_blob)-n+1,n)));
return out_clob;
end;
/
一旦有了此功能,就可以使用它来将BLOB检索为CLOB,显然,我们假设BLOB实际上是存储为二进制对象的字符串。
SELECT BLOB_TO_CHAR(p1_blob => your blob column ) from your table ;
然后,由于输出为CLOB,因此可以应用dbms_lob.substr或任何其他函数。
其他可转换回BLOB的
create or replace function clob_to_blob (p1_clob CLOB) return BLOB is
Result BLOB;
o1 integer;
o2 integer;
c integer;
w integer;
begin
o1 := 1;
o2 := 1;
c := 0;
w := 0;
DBMS_LOB.CreateTemporary(Result, true);
DBMS_LOB.ConvertToBlob(Result, p1_clob, length(p1_clob), o1, o2, 0, c, w);
return(Result);
end clob2blob;
/
一旦您以clob格式应用了在列中所做的任何拆分,就可以使用此函数转换回blob。
希望有帮助