[0831]bbed读取数据块6.txt
[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 "
" | sed "1s///" |tr "" "
"| 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 "
" | sed "1s/^G//" |tr "^G" "
"| 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
以上是 [0831]bbed读取数据块6.txt 的全部内容, 来源链接: utcz.com/z/535894.html