最近在移植的时候需要处理blob和varchar的相互转换,借鉴了别人的思路,写了2个函数,给大家分享下:
--varchar_to_blob
create or replace function varchar_to_blob(v_char in varchar2)
return blob
is
v_blob blob;
v_start int:=1;
v_buffer int:=400;
begin
if dbms_lob.getlength(v_char) is null then
return utl_raw.cast_to_raw('');
else
print dbms_lob.getlength(v_char)/v_buffer;
for j in 1..ceil(length(v_char)) loop
v_blob:=utl_raw.cast_to_raw(dbms_lob.substr(v_char,v_start,1));
v_start:=v_start+1;
end loop;
return v_blob;
end if;
end varchar_to_blob;
--BLOB_TO_VARCHAR
Create or Replace function BLOB_TO_VARCHAR (v_blob in blob) return varchar2
is
v_varchar varchar2(4000);
v_start int:=1;
v_buffer int:=4000;
begin
if dbms_lob.getlength(v_blob) is null then
return '';
else
for j in 1..ceil(dbms_lob.getlength(v_blob)) loop
v_varchar:=utl_raw.cast_to_varchar2(dbms_lob.substr(v_blob,v_start,1));
v_start:=v_start+1;
end loop;
return v_varchar;
end if;
end blob_to_varchar;
文章
阅读量
获赞