在使用Oralce时,直接取出 CLOB 到 CHAR 转换或 BLOB 到 RAW 转换时,会出现ORA-22835的异常,以下是个人的解决方案
1 create or replace Function BlobToVarchar (Blob_In In Blob) Return clob 2 Is 3 V_Varchar Varchar2(32767); 4 V_Varchar1 Varchar2(32767); 5 V_Start Pls_Integer := 1; 6 V_Buffer Pls_Integer := 4000; 7 Begin 8 9 If Dbms_Lob.Getlength(Blob_In) Is Null Then 10 Return ‘‘; 11 End If; 12 V_Varchar1 := ‘‘; 13 --return to_char(Ceil(Dbms_Lob.Getlength(Blob_In) / V_Buffer)); 14 For I In 1..Ceil(Dbms_Lob.Getlength(Blob_In) / V_Buffer) Loop 15 --当转换出来的字符串乱码时,可尝试用注释掉的函数 16 --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‘)); 17 V_Varchar := Utl_Raw.Cast_To_Varchar2(Dbms_Lob.Substr(Blob_In, V_Buffer, V_Start)); 18 V_Varchar1 := V_Varchar1 || V_Varchar; 19 20 V_Start := V_Start + V_Buffer; 21 End Loop; 22 23 Return V_Varchar1; 24 25 End Blob_To_Varchar;
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 = ‘‘ ;
时间: 2024-10-06 05:17:46