突然断电产生LOB大字段的损坏报错通常是ORA-01555: snapshot too old: rollback segment number with name "" too small 或者ORA–00600未知错误等,如果按快照太旧这个根本解决不了问题,因为查询会发现UNDO表空间使用率很低,其实是该表有BLOB或CLOB字段损坏问题造成的,解决方法如下(做前先停止业务):
1.创建表存放lob损坏行的rowid
create table corrupted_lob_data_cbill_cloud (corrupt_rowid rowid, err_num number);
2.执行如下plsql块,找出存在损坏lob的行
declare
error_1578 exception;
error_1555 exception;
error_22922 exception;
pragma exception_init(error_1578,-1578);
pragma exception_init(error_1555,-1555);
pragma exception_init(error_22922,-22922);
n number;
begin
for cursor_lob in (select rowid r,c_bill_sign_content from UAA_PENDING_EINVOICE) loop
begin
n := dbms_lob.instr (cursor_lob.c_bill_sign_content, hextoraw ('889911')) ;
exception
when error_1578 then
insert into corrupted_lob_data_cbill_cloud values (cursor_lob.r, 1578);
commit;
when error_1555 then
insert into corrupted_lob_data_cbill_cloud values (cursor_lob.r, 1555);
commit;
when error_22922 then
insert into corrupted_lob_data_cbill_cloud values (cursor_lob.r, 22922);
commit;
end;
end loop;
end;
/
update UAA_PENDING_EINVOICE t set c_bill_sign_content = c_bill_sign_content_old where c_bill_sign_content is null and completed=0 ;
3.查询结果查看哪些行 blob列有损坏
select * from corrupted_lob_data_cbill_cloud;
4.将损坏的blob记录删除
删除这个记录,删除前请保存数据,可以右击保存为excel格式
select * from 表 where rowid in (select corrupt_rowid from corrupted_lob_data_cbill_cloud);
delete from 表 where rowid in (select corrupt_rowid from corrupted_lob_data_cbill_cloud);
5.测试下是否正常,如果不正常重新导出导入一份,重新开启业务
expdp 用户/密码 directory=目录名 dumpfile=文件件 logfile=日志名 tables=表名
6.把原表删除,再导入
drop table 表名;
impdp 用户/密码 directory=目录名 dumpfile=文件件 logfile=日志名 tables=表名
7.恢复第4步删除的数据
insert into 表 values (''''''''''''');