4. 下面我们来修改数据
本例子基于11g
先声明,笔者做实验之前已经有了全集备份,也希望大家在做实验的时候做好备份。
首先补充一下基本知识,假设块大小为
8kb=8192byte
1byte=8bit
dump文件使用16进制编码
所以可以使用2个16进制编码代表1byte
因此一个块中总共有8192*2=16384个0到F的代码构成,每2位代表一个字节。
sys@FAKE> select t.*, 2 dbms_rowid.rowid_relative_fno(t.rowid) as "FNO#", 3 dbms_rowid.rowid_block_number(t.rowid) as "BLK#", 4 dbms_rowid.rowid_row_number(t.rowid) as "ROW#" 5 from scott.emp t 6 where t.empno = 7839; EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO FNO# BLK# ROW#---------- ---------- --------- ---------- --------- ---------- ---------- ---------- ---------- ---------- ---------- 7839 KING PRESIDENT 17-NOV-81 5000 10 4 29 8
就来修改一下emp 表中 的 7839 这条记录把 修改sal为4000
先来看一下5000的十六制码是多少
sys@FAKE> select dump(5000,1016) from dual;DUMP(5000,1016)------------------Typ=2 Len=2: c2,33
使用十六进制码查找一下
BBED> find /x c233
File: /u01/apps/oracle/oradata/fake/users01.dbf (4)
Block: 29 Offsets: 7850 to 8191 Dba:0x0100001d
------------------------------------------------------------------------
c233ff02 c10b2c01 0803c24e 59055343 4f545407 414e414c 59535403 c24c4307
77bb0413 01010102 c21fff02 c1152c01 0803c24e 5305434c 41524b07 4d414e41
47455203 c24f2807 77b50609 01010103 c21933ff 02c10b2c 010803c2 4d630542
4c414b45 074d414e 41474552 03c24f28 0777b505 01010101 03c21d33 ff02c11f
2c010803 c24d3706 4d415254 494e0853 414c4553 4d414e03 c24d6307 77b5091c
01010103 c20d3302 c20f02c1 1f2c0108 03c24c43 054a4f4e 4553074d 414e4147
455203c2 4f280777 b5040201 010103c2 1e4cff02 c1152c01 0803c24c 16045741
52440853 414c4553 4d414e03 c24d6307 77b50216 01010103 c20d3302 c20602c1
1f2c0108 03c24b64 05414c4c 454e0853 414c4553 4d414e03 c24d6307 77b50214
01010102 c21102c2 0402c11f 2c010803 c24a4605 534d4954 4805434c 45524b03
c2500307 77b40c11 01010102 c209ff02 c1151006 eece
<32 bytes per line>
offset=7850
查看一下4000的十六进制码
sys@FAKE> select dump(4000.00,1016) from dual;DUMP(4000.00,1016)------------------Typ=2 Len=2: c2,29sys@FAKE> select dump(4000.00,1016) from dual;DUMP(4000.00,1016)------------------Typ=2 Len=2: c2,29
BBED> set offset 7850
OFFSET 7850
BBED> m /x c229
BBED-00215: editing not allowed in BROWSE mode
BBED> set mode edit
MODE Edit
BBED> m /x c229
File: /u01/apps/oracle/oradata/fake/users01.dbf (4)
Block: 29 Offsets: 7850 to 7977 Dba:0x0100001d
-----------------------------------------------------------------------
c229ff02 c10b2c01 0803c24e 59055343 4f545407 414e414c 59535403 c24c4307
77bb0413 01010102 c21fff02 c1152c01 0803c24e 5305434c 41524b07 4d414e41
47455203 c24f2807 77b50609 01010103 c21933ff 02c10b2c 010803c2 4d630542
4c414b45 074d414e 41474552 03c24f28 0777b505 01010101 03c21d33 ff02c11f
<32 bytes per line>
生效
BBED> sum
Check value for File 4, Block 29:
current = 0xc587, required = 0xdf87
BBED> sum apply
Check value for File 4, Block 29:
current = 0xdf87, required = 0xdf87
BBED> verify
DBVERIFY - Verification starting
FILE = /u01/apps/oracle/oradata/fake/users01.dbf
BLOCK = 29
DBVERIFY - Verification complete
Total Blocks Examined : 1
Total Blocks Processed (Data) : 1
Total Blocks Failing (Data) : 0
Total Blocks Processed (Index): 0
Total Blocks Failing (Index): 0
Total Blocks Empty : 0
Total Blocks Marked Corrupt : 0
Total Blocks Influx : 0
Message 531 not found; product=RDBMS; facility=BBED
查询没有变?
sys@FAKE> alter system flush buffer_cache;System altered.
再次查询
sys@FAKE> select t.*, 2 dbms_rowid.rowid_relative_fno(t.rowid) as "FNO#", 3 dbms_rowid.rowid_block_number(t.rowid) as "BLK#", 4 dbms_rowid.rowid_row_number(t.rowid) as "ROW#" 5 from scott.emp t 6 where t.empno = 7839; EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO FNO# BLK# ROW#---------- ---------- --------- ---------- --------- ---------- ---------- ---------- ---------- ---------- ---------- 7839 KING PRESIDENT 17-NOV-81 4000 10 4 29 8
注意:这里修改的字节数必须和原来相同。
比如5000十六进制为c233
你不能直接修改为c21f33,这样会覆盖已有数据毁坏,出现类似下面的情况
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO FNO# BLK# ROW#---------- ---------- --------- ---------- --------- ---------- ---------- ---------- ---------- ---------- ---------- 7839 KING PRESIDENT 17-NOV-81 3000 -k.91E+120 -3.619E-27 4 29 8
|