Use bbed to modify data and bbed to modify data
Bbed is a powerful tool that allows us to directly modify the corresponding content from the data file without bypassing oracle.
ZBDBA@orcl11g>select * from emp; EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO---------- -------------------- ------------------ ---------- ------------ ---------- ---------- ---------- 7499 ALLEN SALESMAN 7698 20-FEB-81 1600 300 30 7521 WARD SALESMAN 7698 22-FEB-81 1250 500 30 7566 JONES MANAGER 7839 02-APR-81 2975 20 7654 MARTIN SALESMAN 7698 28-SEP-81 1250 1400 30 7698 BLAKE MANAGER 7839 01-MAY-81 2850 30 7782 CLARK MANAGER 7839 09-JUN-81 2450 10 7788 SCOTT ANALYST 7566 19-APR-87 3000 20 7839 KING PRESIDENT 17-NOV-81 5000 10 7844 TURNER SALESMAN 7698 08-SEP-81 1500 0 30 7876 ADAMS CLERK 7788 23-MAY-87 1100 20 7900 JAMES CLERK 7698 03-DEC-81 950 30 7902 FORD ANALYST 7566 03-DEC-81 3000 20 7934 MILLER CLERK 7782 23-JAN-82 1300 1013 rows selected.
Here we can view the physical block number corresponding to this table.
ZBDBA@orcl11g>select rowid,dbms_rowid.rowid_object(rowid) robject, 2 dbms_rowid.rowid_relative_fno(rowid) fno, 3 dbms_rowid.rowid_block_number(rowid) bno, 4 dbms_rowid.rowid_row_number(rowid) rno from emp where rownum=1;ROWID ROBJECT FNO BNO RNO------------------ ---------- ---------- ---------- ----------AAASKaAAGAAAACDAAA 74394 6 131
Modify with bbed
BBED> set file 6 block 131 FILE# 6 BLOCK# 131BBED> mapFile: /opt/oracle/oradata/orcl11g/zbdba01.dbf (6)Block: 131 Dba:0x01800083------------------------------------------------------------KTB Data Block (Table/Cluster)struct kcbh, 20 bytes @0 struct ktbbh, 96 bytes @20 struct kdbh, 14 bytes @124 struct kdbt[1], 4 bytes @138 sb2 kdbr[13] @142 ub1 freespace[7491] @168 ub1 rowdata[529] @7659 ub4 tailchk @8188
Find SCOTT in string format
BBED> find /c SCOTTFile: /opt/oracle/oradata/orcl11g/zbdba01.dbf (6)Block: 131 Offsets: 7902 to 8191 Dba:0x01800083------------------------------------------------------------------------53434f54 5407414e 414c5953 5403c24c 430777bb 04130101 0102c21f ff02c1152c000803 c24e5305 434c4152 4b074d41 4e414745 5203c24f 280777b5 060901010103c219 33ff02c1 0b2c0008 03c24d63 05424c41 4b45074d 414e4147 455203c24f280777 b5050101 010103c2 1d33ff02 c11f2c00 0803c24d 37064d41 5254494e0853414c 45534d41 4e03c24d 630777b5 091c0101 0103c20d 3302c20f 02c11f2c000803c2 4c43054a 4f4e4553 074d414e 41474552 03c24f28 0777b504 0201010103c21e4c ff02c115 2c000803 c24c1604 57415244 0853414c 45534d41 4e03c24d630777b5 02160101 0103c20d 3302c206 02c11f2c 000803c2 4b640541 4c4c454e0853414c 45534d41 4e03c24d 630777b5 02140101 0102c211 02c20402 c11f0206c656<32 bytes per line>
Dump to see if it is what we need:
BBED> d /v offset 7902 count 128File: /opt/oracle/oradata/orcl11g/zbdba01.dbf (6)Block: 131 Offsets: 7902 to 8029 Dba:0x01800083-------------------------------------------------------53434f54 5407414e 414c5953 5403c24c l SCOTT.ANALYST..L430777bb 04130101 0102c21f ff02c115 l C.w.............2c000803 c24e5305 434c4152 4b074d41 l ,....NS.CLARK.MA4e414745 5203c24f 280777b5 06090101 l NAGER..O(.w.....0103c219 33ff02c1 0b2c0008 03c24d63 l ....3....,....Mc05424c41 4b45074d 414e4147 455203c2 l .BLAKE.MANAGER..4f280777 b5050101 010103c2 1d33ff02 l O(.w.........3..c11f2c00 0803c24d 37064d41 5254494e l ..,....M7.MARTIN<16 bytes per line>BBED> d /v offset 7902 count 12File: /opt/oracle/oradata/orcl11g/zbdba01.dbf (6)Block: 131 Offsets: 7902 to 7913 Dba:0x01800083-------------------------------------------------------53434f54 5407414e 414c5953 l SCOTT.ANALYS<16 bytes per line>BBED> modify /c 'ZBDBA' offset 7902Warning: contents of previous BIFILE will be lost. Proceed? (Y/N) yFile: /opt/oracle/oradata/orcl11g/zbdba01.dbf (6)Block: 131 Offsets: 7902 to 7913 Dba:0x01800083------------------------------------------------------------------------5a424442 4107414e 414c5953<32 bytes per line>BBED> d /v offset 7902 count 12File: /opt/oracle/oradata/orcl11g/zbdba01.dbf (6)Block: 131 Offsets: 7902 to 7913 Dba:0x01800083-------------------------------------------------------5a424442 4107414e 414c5953 l ZBDBA.ANALYS<16 bytes per line>BBED> sum applyCheck value for File 6, Block 131:current = 0x60f5, required = 0x60f5BBED> verifyDBVERIFY - Verification startingFILE = /opt/oracle/oradata/orcl11g/zbdba01.dbfBLOCK = 131DBVERIFY - Verification completeTotal Blocks Examined : 1Total Blocks Processed (Data) : 1Total Blocks Failing (Data) : 0Total Blocks Processed (Index): 0Total Blocks Failing (Index): 0Total Blocks Empty : 0Total Blocks Marked Corrupt : 0Total Blocks Influx : 0Message 531 not found; product=RDBMS; facility=BBEDBBED>
Cache Refresh:
Alter system flush buffer_cache; check whether the modification is successful: ZBDBA @ orcl11g> select * from emp; empno ename job mgr hiredate sal comm deptno ---------- zookeeper ---------- ------------ ---------- 7499 allen salesman 7698 20-FEB-81 1600 300 30 7521 ward salesman 7698 million 1250 500 martin salesman 7698 28-SEP-81 1250 1400 30 7698 blake manager 7839 01-MAY-81 2850 30 7782 clark manager 7839 09-JUN-81 2450 10 7788 zbdba king president 17-NOV-81 5000 10 7844 turner salesman 7698 08-SEP-81 1500 0 30 7876 adams clerk 7788 23-MAY-87 1100 20 7900 james clerk 7698 03-DEC-81 950 30 7902 ford analyst 7566 03-DEC-81 3000 20 7934 miller clerk 7782 23-JAN-82 1300 10
What is the bbed tool? I heard that the oracle database has a very powerful bbed tool.
"BBED (Oracle Block Brower and EDitor Tool) is a Tool used to directly view and modify data file data. It is an internal Oracle Tool that can directly modify the content of Oracle data file blocks, it is simply a binary editing tool for Oracle. This tool is not supported by Oracle, so it does not generate executable files by default, and needs to be re-compiled before use ."
Compiling the tool in 10 Gb is relatively simple:
[Maclean @ rh2 ~] $ Cd $ ORACLE_HOME/rdbms/lib
[Maclean @ rh2 lib] $ make-f ins_rdbms.mk $ ORACLE_HOME/rdbms/lib/bbed
Make: '/s01/10gdb/rdbms/lib/bbed' is up to date.
[Maclean @ rh2 lib] $ rm bbed
[Maclean @ rh2 lib] $ make-f ins_rdbms.mk $ ORACLE_HOME/rdbms/lib/bbed
Linking BBED utility (bbed)
Rm-f/s01/10gdb/rdbms/lib/bbed
Gcc-o/s01/10gdb/rdbms/lib/bbed-L/s01/10gdb/rdbms/lib/-L/s01/10gdb/lib/-L/s01/10gdb/ lib/stubs // s01/10gdb/lib/s0main. o/s01/10gdb/rdbms/lib/ssbbded. o/s01/10gdb/rdbms/lib/sbbdpt. o 'cat/s01/10gdb/lib/ldflags '-lnsslb10-lncrypt10-lnsgr10-lnzjs10-ln10-lnnz10-lnl10/s01/10gdb/rdbms/lib/defopt. o-ldbtools10-lclntsh 'cat/s01/10gdb/lib/ldflags '-lnsslb10-lncrypt10-lnsgr10-signature-ln10-lnnz10-lnl10-lnro10' cat/s01/10gdb /ldflags '-signature-lncrypt10-signature-ln10-signature-lnl10-lclient10-lnnetd10-lvsn10-lcommon10-lgeneric10-lmm-signature-lnls10-lcore10-signature lnls10- lcore10-lsnls10-lnls10-lxml10-lcore10-lunls10-lsnls10-lnls10-lcore10-lnls10 'cat &#...... remaining full text>
How to Use bbed to view the file id of the data file
BBED> info all File # Name Size (blks) ----- ---- ---------- 1/u01/app/oracle/oradata/repo/system01.dbf 93440 2/u01/app/oracle/oradata/repo/sysaux01.dbf 98560 3/u01/app/oracle/oradata /repo/undotbs01.dbf 12160 4/u01/app/oracle/oradata/repo/users01.dbf 2080 5/u01/app/oracle/oradata/repo/example01.dbf 44240 6/u01/app/oracle /oradata/repo/bbedtb01.dbf 1280 7/u01/app/oracle/oradata/repo/bbedtb02.dbf 1280 BBED> set dba 5, 1 DBA 0x01400001 (20971521, 1) BBED> p kcvfhrfnub4 kcvfhrfn @ 368 0x00000005
Zero x 00000005
View the fileheader.