[20150612]使用bvi查看数据块.txt
--编写一个简单的脚本实现bvi查看数据块,主要我现在喜欢使用bbed查看,而修改选择bvi。
--通过例子来说明:
SCOTT@test> select rowid,dept.* from dept ;
ROWID DEPTNO DNAME LOC
------------------ ------------ -------------- -------------
AABJVUAAEAAAAdzAAA 10 ACCOUNTING NEW YORK
AABJVUAAEAAAAdzAAB 20 RESEARCH DALLAS1
AABJVUAAEAAAAdzAAC 30 SALES CHICAGO
AABJVUAAEAAAAdzAAD 40 OPERATIONS BOSTON
AABJVUAAEAAAAd3AAA 50 MARKETING LONDON
SCOTT@test> @ lookup_rowid AABJVUAAEAAAAdzAAA
OBJECT FILE BLOCK ROW DBA TEXT
------------ ------------ ------------ ------------ -------------------- ----------------------------------------
300372 4 1907 0 4,1907 alter system dump datafile 4 block 1907
--如果通过bvi查看要先算偏移量,1907*block_size = 1907*8192=15622144.然后执行:
bvi -b 15622144 -s 8192 /u01/app/oracle11g/oradata/test/users01.dbf
$ cat bbvi.sql
column bvi_command format a90
select 'bvi -b '|| &2*BLOCK_SIZE||' -s '||block_size||' '||NAME bvi_command from v$datafile where file#=&1 ;
--顺便练习写一个shell脚本:
$ cat bbvi
#! /bin/bash
# convert bvi runnning format
# bbvi file# block#
# $1 = file# $2 = block#
if [ $# -ne 2 ] ; then
echo
echo "USAGE: $0 file# block#"
echo
exit 1;
fi
bvi_command=`sqlplus -S / as sysdba set pagesize 0 feedback off verify off heading off echo off
select 'bvi -b '|| \$2*BLOCK_SIZE ||' -s '||block_size||' '||NAME bvi_command from v\\$datafile where file#=\$1 ;
exit;
END`
if [ -z "$bvi_command" ]; then
echo "No rows returned from database"
exit 0
else
echo
read -p "press ctrl+c break, press return run .. $bvi_command "
echo
eval $bvi_command
fi