在使用Oralce时,直接取出 CLOB 到 CHAR 转换或 BLOB 到 RAW 转换时,会出现ORA-22835的异常,以下是个人的解决方案
create or replace Function BlobToVarchar (Blob_In In Blob) Return clob
Is
V_Varchar Varchar2(32767);
V_Varchar1 Varchar2(32767);
V_Start Pls_Integer := 1;
V_Buffer Pls_Integer := 4000;
Begin
If Dbms_Lob.Getlength(Blob_In) Is Null Then
Return '';
End If;
V_Varchar1 := '';
--return to_char(Ceil(Dbms_Lob.Getlength(Blob_In) / V_Buffer));
For I In 1..Ceil(Dbms_Lob.Getlength(Blob_In) / V_Buffer) Loop
--当转换出来的字符串乱码时,可尝试用注释掉的函数
--V_Varchar := Utl_Raw.Cast_To_Varchar2(Utl_Raw.Convert(Dbms_Lob.Substr(Blob_In, V_Buffer, V_Start),'SIMPLIFIED CHINESE_CHINA.ZHS16GBK', 'AMERICAN_THE NETHERLANDS.UTF8'));
V_Varchar := Utl_Raw.Cast_To_Varchar2(Dbms_Lob.Substr(Blob_In, V_Buffer, V_Start));
V_Varchar1 := V_Varchar1 || V_Varchar;
V_Start := V_Start + V_Buffer;
End Loop;
Return V_Varchar1;
End ;
1.首先执行上面的函数,返回的是个clob
2将clob转成varchar2
说白了 就是 to_char(Blob_To_Varchar(字段))
创建二个函数 然后就可以用了,如果说实现 数据库里面大字段的批量替换还是比较方便
update DR_RPT_REPORT_DATASOURCE
set data_sql =
c2b(to_clob((select replace(Blob_To_Varchar(data_sql),'XXX','XXX') from DR_RPT_REPORT_DATASOURCE where data_id
='XXXX' ))) where data_id = '' ;