[20150612]使用bvi檢視資料塊.txt

lfree發表於2015-06-12

[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 << END
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

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/267265/viewspace-1696423/,如需轉載,請註明出處,否則將追究法律責任。

相關文章