[20210831]bbed讀取資料塊6.txt

lfree發表於2021-09-01

[20210831]bbed讀取資料塊6.txt

--//前一段時間使用自己寫的指令碼讀取資料塊,遇到1個小問題,就是欄位串超長就僅僅顯示1段。
--//實際上bbed最大顯示寬度是300,我測試最大顯示275個字元.

1.問題提出:
BBED> set width 300
        WIDTH           300

BBED> set width 301
BBED-00208: out of range WIDTH (301)

$ . fff.sh 1 521 523 59 rnnc | grep -ni undo
8:15 |15|CREATE TABLE UNDO$("US#" NUMBER NOT NULL,"NAME" VARCHAR2(30) NOT NULL,"USER#" NUMBER NOT NULL,"FILE#" NUMBER NOT NULL,"BLOCK#" NUMBER NOT NULL,"SCNBAS" NUMBER,"SCNWRP" NUMBER,"XACTSQN" NUMBER,"UNDOSQN" NUMBER,"INST#" NUMBER,"STATUS$" NUMBER NOT NULL,"TS#" NUMBER,"UGRP#" NUMB
9:34 |34|CREATE UNIQUE INDEX I_UNDO1 ON UNDO$(US#) PCTFREE 10 INITRANS 2 MAXTRANS 255 STORAGE (  INITIAL 64K NEXT 1024K MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE 0 OBJNO 34 EXTENTS (FILE 1 BLOCK 320))
10:35 |35|CREATE INDEX I_UNDO2 ON UNDO$(NAME) PCTFREE 10 INITRANS 2 MAXTRANS 255 STORAGE (  INITIAL 64K NEXT 1024K MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE 0 OBJNO 35 EXTENTS (FILE 1 BLOCK 328))
32:16 |16|CREATE TABLE TS$("TS#" NUMBER NOT NULL,"NAME" VARCHAR2(30) NOT NULL,"OWNER#" NUMBER NOT NULL,"ONLINE$" NUMBER NOT NULL,"CONTENTS$" NUMBER NOT NULL,"UNDOFILE#" NUMBER,"UNDOBLOCK#" NUMBER,"BLOCKSIZE" NUMBER NOT NULL,"INC#" NUMBER NOT NULL,"SCNWRP" NUMBER,"SCNBAS" NUMBER,"DFLMI
--//太長看不出完整語句.不過從前面的行號可以推斷在dba=1,521塊的行7。"

BBED> x /rnnc dba 1,521 *kdbr[7]
rowdata[4739]                               @6029
-------------
flag@6029: 0x2c (KDRHFL, KDRHFF, KDRHFH)
lock@6030: 0x01
cols@6031:    3

col    0[2] @6032: 15
col    1[2] @6035: 15
col  2[600] @6038: CREATE TABLE UNDO$("US#" NUMBER NOT NULL,"NAME" VARCHAR2(30) NOT NULL,"USER#" NUMBER NOT NULL,"FILE#" NUMBER NOT NULL,"BLOCK#" NUMBER NOT NULL,"SCNBAS" NUMBER,"SCNWRP" NUMBER,"XACTSQN" NUMBER,"UNDOSQN" NUMBER,"INST#" NUMBER,"STATUS$" NUMBER NOT NULL,"TS#" NUMBER,"UGRP#" NUMB
ER,"KEEP" NUMBER,"OPTIMAL" NUMBER,"FLAGS" NUMBER,"SPARE1" NUMBER,"SPARE2" NUMBER,"SPARE3" NUMBER,"SPARE4" VARCHAR2(1000),"SPARE5" VARCHAR2(1000),"SPARE6" DATE) PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 STORAGE (  INITIAL 64K NEXT 1024K MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE 0 OBJNO
15 EXTENTS (FILE 1 BLOCK 224))

2.問題解決:

--//花一點點時間改善這個問題,實際上還有許多麻煩事情,比如即使解決了顯示寬度問題,還可能遇到半個漢字的問題,還有如果字元
--//串含有回車換行等字元時,情況更加複雜。這種情況暫時不考慮.
--//注意:sed 命令如果裡面含$,要使用單引號,調式時在這裡浪費許多時間.

$ cat fff.sh
#! /bin/bash -x
# argv1=file_number argv2=begin_block argvs3=end_block argv4=data_object_id argv5=bbed /x format
file_number=$1
begin_block=$2
end_block=$3
data_object_id=$4
ff="/r"${5}

# create sed script.
a=$5
len=$( echo ${#a})
seq $len | xargs -IQ expr substr $a Q 1 | grep -n '[nt]' | sed  's+:.$+s/ $//+' >| ff.sed
echo 's+^\*NULL\*$++g' >> ff.sed

# scan1 begin_block to end_block,define Scope.
/bin/rm scan1.txt 2>/dev/null
while [ $begin_block -le $end_block ]
do
    v_object_id=$(echo "p /d dba $file_number,$begin_block  ktbbh.ktbbhsid.ktbbhod1" | rlbbed | grep ktbbhod1 |awk '{print $NF}')
    if [ -z "$v_object_id" ]
    then
            v_object_id=0
    fi

    if (( $v_object_id == $data_object_id ))
    then
            echo $file_number,$begin_block >> scan1.txt
    fi
    begin_block=$[ begin_block + 1 ]
done

# scan2 kdbr and display record.
cat scan1.txt |while read dba
do
    #echo set dba $dba
    kdbr_size=$(echo map dba $dba | rlbbed | grep "sb2 kdbr" | sed -e "s/^.*\[//;s/].*$//")
    #echo $kdbr_size

    begin=0
    end=$[ kdbr_size -1 ]
    #echo $begin $end

    while [ $begin -le $end ]
    do
        kdbr_off=$(echo p dba $dba offset 0 kdbr | rlbbed | grep "sb2 kdbr\[$begin\]" | awk '{print $NF'})
        #echo $kdbr_off
        #if [ $kdbr_off -gt $kdbr_size ]
        if (( $kdbr_off > $kdbr_size ))
        then
            #echo -n "x $ff dba $dba *kdbr[$begin]" | rlbbed  | grep "^col " | cut -c20- | sed -f ff.sed | paste -sd'|'
            #echo -n "x $ff dba $dba *kdbr[$begin]" | rlbbed | sed -n '/^col /,${s/^col .\{13\}: //;p;}' | sed '/^BBED/,$d' | tr -d "\n\r" | sed "1s///" |tr "" "\n"| sed -f ff.sed| paste -sd"|"
            echo -n "x $ff dba $dba *kdbr[$begin]" | rlbbed | sed -n '/^col /,${s/^col .\{13\}: /^G/;p;}' | sed '/^BBED/,$d' | tr -d "\n\r" | sed "1s/^G//" |tr "^G" "\n"| sed -f ff.sed| paste -sd"|"
        fi
        begin=$[ begin + 1 ]
    done
done

--//^G 表示 ascii(7).
--//在linux下vim的輸入模式,使用如下方法輸入,windows下使用ctrl+q代替ctrl+v
ascii(7) 使用ctrl+v ctrl+g 輸入。
ascii(6) 使用ctrl+v ctrl+f 輸入。

3.測試:
--//改寫後的執行結果如下:
$ . fff.sh 4 151 151 87108 nccntnnn
7369|SMITH|CLERK|7902|1980-12-17 00:00:00|800||20
7499|ALLEN|SALESMAN|7698|1981-02-20 00:00:00|1600|300|30
7521|WARD|SALESMAN|7698|1981-02-22 00:00:00|1250|500|30
7566|JONES|MANAGER|7839|1981-04-02 00:00:00|2975||20
7654|MARTIN|SALESMAN|7698|1981-09-28 00:00:00|1250|1400|30
7698|BLAKE|MANAGER|7839|1981-05-01 00:00:00|2850||30
7782|CLARK|MANAGER|7839|1981-06-09 00:00:00|2450||10
7788|SCOTT|ANALYST|7566|1987-04-19 00:00:00|3000||20
7839|KING|PRESIDENT||1981-11-17 00:00:00|5000||10
7844|TURNER|SALESMAN|7698|1981-09-08 00:00:00|1500|0|30
7876|ADAMS|CLERK|7788|1987-05-23 00:00:00|1100||20
7900|JAMES|CLERK|7698|1981-12-03 00:00:00|950||30
7902|FORD|ANALYST|7566|1981-12-03 00:00:00|3000||20
7934|MILLER|CLERK|7782|1982-01-23 00:00:00|1300||10

$ . fff.sh 1 521 523 59 nnc | grep -ni undo
8:15|15|CREATE TABLE UNDO$("US#" NUMBER NOT NULL,"NAME" VARCHAR2(30) NOT NULL,"USER#" NUMBER NOT NULL,"FILE#" NUMBER NOT NULL,"BLOCK#" NUMBER NOT NULL,"SCNBAS" NUMBER,"SCNWRP" NUMBER,"XACTSQN" NUMBER,"UNDOSQN" NUMBER,"INST#" NUMBER,"STATUS$" NUMBER NOT NULL,"TS#" NUMBER,"UGRP#" NUMBER,"KEEP" NUMBER,"OPTIMAL" NUMBER,"FLAGS" NUMBER,"SPARE1" NUMBER,"SPARE2" NUMBER,"SPARE3" NUMBER,"SPARE4" VARCHAR2(1000),"SPARE5" VARCHAR2(1000),"SPARE6" DATE) PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 STORAGE (  INITIAL 64K NEXT 1024K MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE 0 OBJNO 15 EXTENTS (FILE 1 BLOCK 224))
9:34|34|CREATE UNIQUE INDEX I_UNDO1 ON UNDO$(US#) PCTFREE 10 INITRANS 2 MAXTRANS 255 STORAGE (  INITIAL 64K NEXT 1024K MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE 0 OBJNO 34 EXTENTS (FILE 1 BLOCK 320))
10:35|35|CREATE INDEX I_UNDO2 ON UNDO$(NAME) PCTFREE 10 INITRANS 2 MAXTRANS 255 STORAGE (  INITIAL 64K NEXT 1024K MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE 0 OBJNO 35 EXTENTS (FILE 1 BLOCK 328))
32:16|16|CREATE TABLE TS$("TS#" NUMBER NOT NULL,"NAME" VARCHAR2(30) NOT NULL,"OWNER#" NUMBER NOT NULL,"ONLINE$" NUMBER NOT NULL,"CONTENTS$" NUMBER NOT NULL,"UNDOFILE#" NUMBER,"UNDOBLOCK#" NUMBER,"BLOCKSIZE" NUMBER NOT NULL,"INC#" NUMBER NOT NULL,"SCNWRP" NUMBER,"SCNBAS" NUMBER,"DFLMINEXT" NUMBER NOT NULL,"DFLMAXEXT" NUMBER NOT NULL,"DFLINIT" NUMBER NOT NULL,"DFLINCR" NUMBER NOT NULL,"DFLMINLEN" NUMBER NOT NULL,"DFLEXTPCT" NUMBER NOT NULL,"DFLOGGING" NUMBER NOT NULL,"AFFSTRENGTH" NUMBER NOT NULL,"BITMAPPED" NUMBER NOT NULL,"PLUGGED" NUMBER NOT NULL,"DIRECTALLOWED" NUMBER NOT NULL,"FLAGS" NUMBER NOT NULL,"PITRSCNWRP" NUMBER,"PITRSCNBAS" NUMBER,"OWNERINSTANCE" VARCHAR2(30),"BACKUPOWNER" VARCHAR2(30),"GROUPNAME" VARCHAR2(30),"SPARE1" NUMBER,"SPARE2" NUMBER,"SPARE3" VARCHAR2(1000),"SPARE4" DATE) STORAGE (  OBJNO 16 TABNO 2) CLUSTER C_TS#(TS#)

--//順便測試半個漢字的問題.

SCOTT@book> create table tx (id number ,vc varchar2(30),vx varchar2(400));
Table created.

SCOTT@book> insert into tx values (3,'測試x',lpad('測試',300,'文'));
1 row created.

SCOTT@book> commit ;
Commit complete.

SCOTT@book> select rowid from tx;
ROWID
------------------
AAAW1lAAEAAAALkAAA

SCOTT@book> @ rowid AAAW1lAAEAAAALkAAA
    OBJECT       FILE      BLOCK        ROW ROWID_DBA            DBA                  TEXT
---------- ---------- ---------- ---------- -------------------- -------------------- ----------------------------------------
     93541          4        740          0  0x10002E4           4,740                alter system dump datafile 4 block 740 ;

SCOTT@book> alter system checkpoint ;
System altered.

$ export NLS_LANG=AMERICAN_AMERICA.US7ASCII
$ rlbbed
BBED: Release 2.0.0.0.0 - Limited Production on Wed Sep 1 09:47:04 2021
Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.
************* !!! For Oracle Internal Use only !!! ***************

BBED> set count 64
        COUNT           64

BBED> set width 300
        WIDTH           300

BBED> x /rncc dba 4,740  *kdbr[0]
rowdata[0]                                  @7873
----------
flag@7873: 0x2c (KDRHFL, KDRHFF, KDRHFH)
lock@7874: 0x01
cols@7875:    3

col    0[2] @7876: 3
col    1[5] @7879: 測試x
col  2[300] @7885: 文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文?
奈奈奈奈奈奈奈奈奈奈牟饈?
--//顯示亂碼.bbed設定width 300,每行最大顯示275,這樣出現半個漢字的情況.

--//如果設定 width 299,顯示正常.
BBED> set width 299
        WIDTH           299

BBED> x /rncc dba 4,740  *kdbr[0]
rowdata[0]                                  @7873
----------
flag@7873: 0x2c (KDRHFL, KDRHFF, KDRHFH)
lock@7874: 0x01
cols@7875:    3

col    0[2] @7876: 3
col    1[5] @7879: 測試x
col  2[300] @7885: 文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文
文文文文文文文文文文文測試

$ . fff.sh 4 740 740 93541 ncc > /tmp/aa1.txt
--//使用vim編輯器開啟顯示正常,太長不貼出了.

$ cut -c201- /tmp/aa1.txt
文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文文測試
--//這也驗證了顯示正常.

4.收尾:
--//測試完成注意收尾.不然字符集不對導致插入的中文亂碼問題.
$ export NLS_LANG=AMERICAN_AMERICA.ZHS16GBK


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

相關文章