corrupt block

/*
   This script prompts for an owner and a tbale name. It then created two new tables
   - orignal_table_name_BAD and orignal_table_name_SAVED. If either if these tables exist,
   they are dropped and then recreated. The script then gets a list of extents and blocks
   associated with the table and loops through each block, attempting to select records by
   the rowid and inserts them into the orignical_table_name_SAVED table. Errors are inserted
   into the original_table_name_BAD table.

   Kerry Osborne - Enkitec
*/

prompt
Prompt WARNING: This script may issue a DROP TABLE command. Do not execute it unless you have read through it
Prompt          and are comfortable you know what it does.
Prompt
accept a prompt "Ready? (hit ctl-C to quit)  "
set serveroutput on format wrapped
declare

debug_flag varchar2(1) :='N';
x number := 0;
y number := 0;
v_maxrows number := 200; -- 200 is maximum number of rows per block
v_old_rowid varchar2(30);
v_owner_name varchar2(30) := upper('&owner_name');
v_table_name varchar2(30) := upper('&table_name');
v_bad_table varchar2(40);
v_saved_table varchar2(40);
v_full_table_name varchar2(30);
v_object_id number := 0;
v_sql_insert_saved varchar(256);
v_temp number;
v_last_block number := 0;

e_invalid_rowid exception;
pragma exception_init(e_invalid_rowid,-1410);
e_missing_file exception;
pragma exception_init(e_missing_file,-376);
e_obj_no_longer_exists exception;
pragma exception_init(e_obj_no_longer_exists,-8103);

cursor v_sql_get_blocks is
select file_id, block_id as start_block, (block_id + blocks - 1) as end_block
from dba_extents where upper(owner) = v_owner_name and segment_name = v_table_name
order by file_id, block_id
;

begin
v_bad_table := v_table_name||'_BAD';
v_saved_table := v_table_name||'_SAVED';

select object_id into v_object_id
from dba_objects
where owner = v_owner_name
and object_name = v_table_name
;

begin -- block to create saved table
  select 1 into v_temp
  from dba_tables
  where owner = v_owner_name
  and table_name = v_saved_table;
  if debug_flag = 'Y' then dbms_output.put_line('dropping '||v_owner_name||'.'||v_saved_table); end if;
  execute immediate 'drop table '||v_owner_name||'.'||v_table_name||'_SAVED';
  if debug_flag = 'Y' then dbms_output.put_line('creating '||v_owner_name||'.'||v_saved_table); end if;
  execute immediate 'create table '||v_owner_name||'.'||v_table_name||'_SAVED as select * from '||v_owner_name||'.'||v_table_name||
                    ' where 1=2';
exception when no_data_found then
  if debug_flag = 'Y' then dbms_output.put_line('creating '||v_owner_name||'.'||v_saved_table); end if;
  execute immediate 'create table '||v_owner_name||'.'||v_table_name||'_SAVED as select * from '||v_owner_name||'.'||v_table_name||
                    ' where 1=2';
end;

begin -- block to create bad table
  select 1 into v_temp
  from dba_tables
  where owner = v_owner_name
  and table_name = v_bad_table;
  if debug_flag = 'Y' then dbms_output.put_line('dropping '||v_owner_name||'.'||v_bad_table); end if;
  execute immediate 'drop table '||v_owner_name||'.'||v_table_name||'_BAD';
  if debug_flag = 'Y' then dbms_output.put_line('creating '||v_owner_name||'.'||v_bad_table); end if;
  execute immediate 'create table '||v_owner_name||'.'||v_table_name||'_BAD (old_rowid varchar2(30), '||
                    ' old_file number, old_object number, old_block number, old_row number, error_message varchar2(300))';
exception when no_data_found then
  if debug_flag = 'Y' then dbms_output.put_line('creating '||v_owner_name||'.'||v_bad_table); end if;
  execute immediate 'create table '||v_owner_name||'.'||v_table_name||'_BAD (old_rowid varchar2(30), '||
                    ' old_file number, old_object number, old_block number, old_row number, error_message varchar2(300))';
end;

v_full_table_name := v_owner_name||'.'||v_table_name;

v_sql_insert_saved := 'insert into '||v_owner_name||'.'||v_saved_table||' select * from '||v_full_table_name||
                      ' where ROWID = dbms_rowid.rowid_create(1, :b_obj, :b_file, :b_blk, :v_row)';


for v_uetrec in v_sql_get_blocks loop

        for v_blk in v_uetrec.start_block..v_uetrec.end_block loop
                 if debug_flag = 'Y' then dbms_output.put_line(v_uetrec.file_id||'.'||v_blk); end if;
                 for v_row in 0..v_maxrows loop
                        v_old_rowid := v_uetrec.file_id||'.'||v_blk||'.'||v_row;
                        begin
                             execute immediate v_sql_insert_saved
                               using v_object_id, v_uetrec.file_id, v_blk, v_row;
                             if debug_flag = 'Y' then
                               dbms_output.put_line(v_old_rowid);
                             end if;
                        exception when e_missing_file then
                          if debug_flag = 'Y' then
                            DBMS_OUTPUT.put_line (DBMS_UTILITY.FORMAT_ERROR_STACK||' '||v_old_rowid);
                          else
                            if v_blk != v_last_block then -- only insert one bad record per block
                               execute immediate
                                  'insert into '||v_owner_name||'.'||v_bad_table||' values'||
                                  '(:b_rowid,:b_obj,:b_file,:b_blk,:b_row,:b_error)'
                                  using v_old_rowid, v_object_id, v_uetrec.file_id, v_blk, v_row, DBMS_UTILITY.FORMAT_ERROR_STACK;
                               y := y+1;
                               v_last_block := v_blk;
                            end if;
                          end if;
                        when e_invalid_rowid then null;
                        when e_obj_no_longer_exists then null;
                        when no_data_found then null;
                        when others then
                          if debug_flag = 'Y' then
                            DBMS_OUTPUT.put_line (DBMS_UTILITY.FORMAT_ERROR_STACK||' '||v_old_rowid);
                          else
                               execute immediate
                                  'insert into '||v_owner_name||'.'||v_bad_table||' values'||
                                  '(:b_rowid,:b_obj,:b_file,:b_blk,:b_row,:b_error)'
                                  using v_old_rowid, v_object_id, v_uetrec.file_id, v_blk, v_row, DBMS_UTILITY.FORMAT_ERROR_STACK;
                               y := y+1;
                          end if;
                        end;
                  end loop; -- end of row-loop
         commit; -- save after each block
         end loop; -- end of block-loop
end loop; -- end of uet-loop

execute immediate
'select count(*) from '||v_owner_name||'.'||v_saved_table
into x;

dbms_output.put_line(chr(0));
dbms_output.new_line;
dbms_output.put_line('Saved '||x||' records in '||v_saved_table||'.');
dbms_output.put_line(y||' bads records in '||v_bad_table||'.');

end;
/
undef a

 

==

SQL> @d:/save_rows_for_me.sql

WARNING: This script may issue a DROP TABLE command. Do not execute it unless you have read through it
and are comfortable you know what it does.

Ready? (hit ctl-C to quit)
输入 owner_name 的值:  SYS
原值    8: v_owner_name varchar2(30) := upper('&owner_name');
新值    8: v_owner_name varchar2(30) := upper('SYS');
输入 table_name 的值:  TB_CORRUPT
原值    9: v_table_name varchar2(30) := upper('&table_name');
新值    9: v_table_name varchar2(30) := upper('TB_CORRUPT');


Saved 7755 records in TB_CORRUPT_SAVED.
603 bads records in TB_CORRUPT_BAD.

PL/SQL 过程已成功完成。

SQL>


============

select /*+ index (messed_up_object  mess_up_object_pk) */ indexed_column1, indexed_column2
from messed_up_object
where rowid in (select dbms_rowid.rowid_create(1,object,file,block,row) from bad_rows_table);


==========

========$$$$save========

/*
   This script prompts for an owner and a tbale name. It then created two new tables
   - orignal_table_name_BAD and orignal_table_name_SAVED. If either if these tables exist,
   they are dropped and then recreated. The script then gets a list of extents and blocks
   associated with the table and loops through each block, attempting to select records by
   the rowid and inserts them into the orignical_table_name_SAVED table. Errors are inserted
   into the original_table_name_BAD table.

   Kerry Osborne - Enkitec
*/

prompt
Prompt WARNING: This script may issue a DROP TABLE command. Do not execute it unless you have read through it
Prompt          and are comfortable you know what it does.
Prompt
accept a prompt "Ready? (hit ctl-C to quit)  "
set serveroutput on format wrapped
declare

debug_flag varchar2(1) :='N';
x number := 0;
y number := 0;
v_maxrows number := 200; -- 200 is maximum number of rows per block
v_old_rowid varchar2(30);
v_owner_name varchar2(30) := upper('&owner_name');
v_table_name varchar2(30) := upper('&table_name');
v_bad_table varchar2(40);
v_saved_table varchar2(40);
v_full_table_name varchar2(30);
v_object_id number := 0;
v_sql_insert_saved varchar(256);
v_temp number;
v_last_block number := 0;

e_invalid_rowid exception;
pragma exception_init(e_invalid_rowid,-1410);
e_missing_file exception;
pragma exception_init(e_missing_file,-376);
e_obj_no_longer_exists exception;
pragma exception_init(e_obj_no_longer_exists,-8103);

cursor v_sql_get_blocks is
select file_id, block_id as start_block, (block_id + blocks - 1) as end_block
from dba_extents where upper(owner) = v_owner_name and segment_name = v_table_name
order by file_id, block_id
;

begin
v_bad_table := v_table_name||'_BAD';
v_saved_table := v_table_name||'_SAVED';

select object_id into v_object_id
from dba_objects
where owner = v_owner_name
and object_name = v_table_name
;

begin -- block to create saved table
  select 1 into v_temp
  from dba_tables
  where owner = v_owner_name
  and table_name = v_saved_table;
  if debug_flag = 'Y' then dbms_output.put_line('dropping '||v_owner_name||'.'||v_saved_table); end if;
  execute immediate 'drop table '||v_owner_name||'.'||v_table_name||'_SAVED';
  if debug_flag = 'Y' then dbms_output.put_line('creating '||v_owner_name||'.'||v_saved_table); end if;
  execute immediate 'create table '||v_owner_name||'.'||v_table_name||'_SAVED as select * from '||v_owner_name||'.'||v_table_name||
                    ' where 1=2';
exception when no_data_found then
  if debug_flag = 'Y' then dbms_output.put_line('creating '||v_owner_name||'.'||v_saved_table); end if;
  execute immediate 'create table '||v_owner_name||'.'||v_table_name||'_SAVED as select * from '||v_owner_name||'.'||v_table_name||
                    ' where 1=2';
end;

begin -- block to create bad table
  select 1 into v_temp
  from dba_tables
  where owner = v_owner_name
  and table_name = v_bad_table;
  if debug_flag = 'Y' then dbms_output.put_line('dropping '||v_owner_name||'.'||v_bad_table); end if;
  execute immediate 'drop table '||v_owner_name||'.'||v_table_name||'_BAD';
  if debug_flag = 'Y' then dbms_output.put_line('creating '||v_owner_name||'.'||v_bad_table); end if;
  execute immediate 'create table '||v_owner_name||'.'||v_table_name||'_BAD (old_rowid varchar2(30), '||
                    ' old_file number, old_object number, old_block number, old_row number, error_message varchar2(300))';
exception when no_data_found then
  if debug_flag = 'Y' then dbms_output.put_line('creating '||v_owner_name||'.'||v_bad_table); end if;
  execute immediate 'create table '||v_owner_name||'.'||v_table_name||'_BAD (old_rowid varchar2(30), '||
                    ' old_file number, old_object number, old_block number, old_row number, error_message varchar2(300))';
end;

v_full_table_name := v_owner_name||'.'||v_table_name;

v_sql_insert_saved := 'insert into '||v_owner_name||'.'||v_saved_table||' select * from '||v_full_table_name||
                      ' where ROWID = dbms_rowid.rowid_create(1, :b_obj, :b_file, :b_blk, :v_row)';


for v_uetrec in v_sql_get_blocks loop

        for v_blk in v_uetrec.start_block..v_uetrec.end_block loop
                 if debug_flag = 'Y' then dbms_output.put_line(v_uetrec.file_id||'.'||v_blk); end if;
                 for v_row in 0..v_maxrows loop
                        v_old_rowid := v_uetrec.file_id||'.'||v_blk||'.'||v_row;
                        begin
                             execute immediate v_sql_insert_saved
                               using v_object_id, v_uetrec.file_id, v_blk, v_row;
                             if debug_flag = 'Y' then
                               dbms_output.put_line(v_old_rowid);
                             end if;
                        exception when e_missing_file then
                          if debug_flag = 'Y' then
                            DBMS_OUTPUT.put_line (DBMS_UTILITY.FORMAT_ERROR_STACK||' '||v_old_rowid);
                          else
                            if v_blk != v_last_block then -- only insert one bad record per block
                               execute immediate
                                  'insert into '||v_owner_name||'.'||v_bad_table||' values'||
                                  '(:b_rowid,:b_obj,:b_file,:b_blk,:b_row,:b_error)'
                                  using v_old_rowid, v_object_id, v_uetrec.file_id, v_blk, v_row, DBMS_UTILITY.FORMAT_ERROR_STACK;
                               y := y+1;
                               v_last_block := v_blk;
                            end if;
                          end if;
                        when e_invalid_rowid then null;
                        when e_obj_no_longer_exists then null;
                        when no_data_found then null;
                        when others then
                          if debug_flag = 'Y' then
                            DBMS_OUTPUT.put_line (DBMS_UTILITY.FORMAT_ERROR_STACK||' '||v_old_rowid);
                          else
                               execute immediate
                                  'insert into '||v_owner_name||'.'||v_bad_table||' values'||
                                  '(:b_rowid,:b_obj,:b_file,:b_blk,:b_row,:b_error)'
                                  using v_old_rowid, v_object_id, v_uetrec.file_id, v_blk, v_row, DBMS_UTILITY.FORMAT_ERROR_STACK;
                               y := y+1;
                          end if;
                        end;
                  end loop; -- end of row-loop
         commit; -- save after each block
         end loop; -- end of block-loop
end loop; -- end of uet-loop

execute immediate
'select count(*) from '||v_owner_name||'.'||v_saved_table
into x;

dbms_output.put_line(chr(0));
dbms_output.new_line;
dbms_output.put_line('Saved '||x||' records in '||v_saved_table||'.');
dbms_output.put_line(y||' bads records in '||v_bad_table||'.');

end;
/
undef a

 


========$$$$obj========

select file_id, block_id as start_block, (block_id + blocks - 1) as end_block, blocks
from dba_extents
where owner like nvl('&owner',owner)
and segment_name like nvl('&segment_name','doda')
order by file_id, start_block
;

========$$$$========

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
计算机中的"corrupt character"是指在文本或文件中出现错误或无法正确识别的字符。这些字符可能是由于编码问题、数据损坏或传输错误等原因引起的。 在计算机中,文本和文件通常以二进制编码形式储存。常见的编码方式包括ASCII、Unicode等。然而,有时候在文本或文件中可能会出现无法正确表示的字符,这就是"corrupt character"。当计算机无法正确处理这些字符时,可能会导致文本显示乱码、文件损坏或无法解析等问题。 造成这种问题的原因多种多样。一种常见的情况是文件传输中出现错误,导致部分数据丢失或损坏。另一种情况是在不同的编码方式之间进行转换时出现错误,导致字符无法正确解释。此外,计算机病毒或恶意软件也可能会修改文本或文件的内容,引入corrupt character。 解决corrupt character的问题需要根据具体情况采取不同的方法。首先,可以尝试使用不同的文本编辑软件或文件查看工具,以确定corrupt character的具体位置和内容。然后,可以尝试修复或恢复数据,例如使用备份文件、修复工具或数据恢复软件来修复受损的文件。另外,也可以通过重新编码、转换或清洁文本数据来避免或纠正corrupt character的出现。 总之,corrupt character在计算机中是指文本或文件中出现的错误或无法正确识别的字符。了解其原因并采取相应的措施可以解决这一问题。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值