[20170611]关于数据块地址的计算.txt

[20170611]关于数据块地址的计算.txt

--//如果数据库出现一些问题,会在alert或者跟踪文件,或者屏幕出现一些错误提示.例如:

ORA-00600: internal error code, arguments: [2662], [3], [392066208], [3], [392066212], [4194825], [], [], [], [], [], []

ORA-600 [2662] [a] [b] {c} [d] [e]
Arg [a] Current SCN WRAP
Arg [b] Current SCN BASE
Arg {c} dependent SCN WRAP
Arg [d] dependent SCN BASE
Arg [e] Where present this is the DBA where the dependent SCN came from.

--//这里第5个参数4194825就是dba也就是数据块地址.
--//实际上简单的计算很简单,32位占4个字节,前10位表示文件号,后22位表示:

SYS@test> select round(&dba/power(2,22),0) file# ,mod(&&dba,power(2,22)) block# from dual ;
old   1: select round(&dba/power(2,22),0) file# ,mod(&&dba,power(2,22)) block# from dual
new   1: select round(4194825/power(2,22),0) file# ,mod(4194825,power(2,22)) block# from dual
     FILE#     BLOCK#
---------- ----------
         1        521


--//我自己常用的脚本:
$ cat dfb10.sql
select
dbms_utility.data_block_address_file(&1) rfile#,
dbms_utility.data_block_address_block(&&1) block#
from dual;

select 'alter system dump datafile '||dbms_utility.data_block_address_file(&1)||' block '||
dbms_utility.data_block_address_block(&&1) ||' ;' text

$ cat dfb16.sql
column text format a60

select
dbms_utility.data_block_address_file(to_number(substr('&&1',3),'xxxxxxxxxxxxxxxx')) rfile#,
dbms_utility.data_block_address_block(to_number(substr('&&1',3),'xxxxxxxxxxxxxxxx')) block#,
'alter system dump datafile '||dbms_utility.data_block_address_file(to_number(substr('&1',3),'xxxxxxxxxxxxxxxx'))||' block '|| dbms_utility.data_block_address_block(to_number(substr('&&1',3),'xxxxxxxxxxxxxxxx')) ||' ;' text
from dual;

--//convert file#,block# 到 dba地址.
$ cat convrdba.sql
select
 TO_CHAR (dbms_utility.make_data_block_address(&1,&2), 'xxxxxxxxxxxxx') rdba16,
dbms_utility.make_data_block_address(&&1,&&2) rdba
from dual;

--//还有1种方法就是bbed,直接输入例子:

BBED> set dba 1,521
        DBA             0x00400209 (4194825 1,521)

BBED> set dba 4194825
        DBA             0x00400209 (4194825 1,521)

BBED> set dba 0x00400209
        DBA             0x00400209 (4194825 1,521)

--//下午无聊,想完善以前[20121207]vim中使用bc做10与16进制计算.txt,链接http://blog.itpub.net/267265/viewspace-750731/
--//源代码http://www.vim.org/scripts/script.php?script_id=219,我修改加入10,16进制的计算,
--//作者这么多年2017/04/17 更新.以此为基础加入10,16进制转化,以及dba转化为file#,block#.
--//这次修改代码加入dba的计算.同时修复了windows下的许多问题.

--//做一些简单说明,这个版本仅仅工作在windows版本.bc的安装可以下载UnxUtils.zip包,设置好PATH路径就ok了.
--//我注解 let str = escape (str, '*();&><|^') ,这样运算存在*以及(),不再存在问题.
--//以前旧版本不支持幂运算(^),windows的转化4个^才能正确执行.

--//简单操作:
a3

在数字a3上面输入10,相当于a3当作16进制数据,给出结果=163.
在数字a3处于选择模式,输入;10,相当于a3当作16进制数据,在提示行上给出答案
(注:windows下要处于可视模式,不能处于选择模式,使用ctrl+g切换)

123
在数字123上面输入16,相当于123当作10进制数据,给出结果=0x7b.
在数字123处于选择模式,输入;16,相当于123当作10进制数据,在提示行上给出答案

x 可以进行行运算
c 在提示行输出结果.

;bc 选中文本,然后ctrl+g,输入;bc,在提示行输出结果.

22
;22

--//参考10,16进制的计算,计算dba转化为file#,block#.
--//做一个操作例子:
4194825 = set dba 1,521
--//打入22,输出如下:
4194825 = set dba 1,521

==================修改后代码如下:
"" calculate expression entered on command line and give answer, e.g.:
" :Calculate sin (3) + sin (4) ^ 2
command! -nargs=+ Calculate echo "<args> = " . Calculate ("<args>")

"" calculate expression from selection, pick a mapping, or use the Leader form
"vnoremap ;bc "ey`>:call CalcLines()<CR>
"vnoremap <Leader>bc "ey`>:call<SID>CalcBC(1)<CR>
vnoremap ;bc "ey`>:call CalcLines(0)<CR>
vnoremap ;10 "ey`>:call CalcLines(10)<CR>
vnoremap ;16 "ey`>:call CalcLines(16)<CR>
vnoremap ;22 "ey`>:call CalcLines(22)<CR>
vnoremap ;32 "ey`>:call CalcLines(32)<CR>

"" calculate expression on current line, pick a mapping, or use the Leader
nnoremap  <Leader>bc "eyy$:call CalcLines(0)<CR>
nnoremap   <Leader>bx <Esc>A=<Esc>"eyy:call CalcLines(0)<CR>
nnoremap   <Leader>10 <Esc>A=<Esc>"eyy:call CalcLines(10)<CR>
nnoremap   <Leader>16 <Esc>A=<Esc>"eyy:call CalcLines(16)<CR>
nnoremap   <Leader>22 <Esc>A=<Esc>"eyy:call CalcLines(22)<CR>
nnoremap   <Leader>32 <Esc>A=<Esc>"eyy:call CalcLines(32)<CR>


"nnoremap  <Leader>bc "eyy$:call<SID>CalcBC(0)<CR>

"" calculate from insertmode
inoremap =: = <Esc>"eyy:call CalcLines()<CR>a

" ---------------------------------------------------------------------
"  Calculate:
"    clean up an expression, pass it to bc, return answer
function! Calculate (s,flag)

    let str = a:s

    " remove newlines and trailing spaces
    let str = substitute (str, " ",   "", "g")
    let str = substitute (str, 's*$', "", "g")

    " sub common func names for bc equivalent
    let str = substitute (str, 'csins*(',  's (', 'g')
    let str = substitute (str, 'ccoss*(',  'c (', 'g')
    let str = substitute (str, 'catans*(', 'a (', 'g')
    let str = substitute (str, "clns*(",   'l (', 'g')
    let str = substitute (str, 'clogs*(',  'l (', 'g')
    let str = substitute (str, 'cexps*(',  'e (', 'g')

    " alternate exponitiation symbols
    let str = substitute (str, '**', '^', "g")
    let str = substitute (str, '`', '^',    "g")
    let str = substitute (str, '^', '^^^^',    "g")

    " escape chars for shell
    " let str = escape (str, '*();&><|^')

    let preload = exists ("g:bccalc_preload") ? g:bccalc_preload : ""

    " run bc
    " return str
    " let answer = system ("echo " . str . " | bc -l " . preload)

    if a:flag == 0
         let answer = system ("echo " . str . " | bc -l " . preload)
    endif
    if a:flag == 16
         let answer = system ("echo obase=16 ;" . str .  " | bc -l " . preload)
         let answer = "0x" . tolower ( answer )
    endif
    if a:flag == 10
         let str = toupper ( str )
         let answer = system ("echo ibase=16 ;" . str .  " | bc -l " . preload)
    endif
    if a:flag == 22
         let answer = system ("echo " . str . "/4194304" . " | bc " . preload)
         let answer1 = system ("echo " . str . "%4194304" . " | bc " . preload)
         let answer = " set dba " . answer . "," . answer1
    endif

    if a:flag == 32
         let answer = system ("echo " . str . "/4294967296" . " | bc " . preload)
         let answer1 = system ("echo " . str . "%4294967296" . " | bc " . preload)
         let answer = " scn_wrap,scn_base: " . answer . " " . answer1
    endif

    " strip newline
    let answer = substitute (answer, " ", "", "g")

    " strip trailing 0s in decimals
    let answer = substitute (answer, '.(d*[1-9])0+', '.1', "")

    return answer
endfunction

" ---------------------------------------------------------------------
" CalcLines:
"
" take expression from lines, either visually selected or the current line,
" pass to calculate function, echo or past answer after '='
function! CalcLines(flag)

    let has_equal = 0

    " remove newlines and trailing spaces
    let @e = substitute (@e, " ", "",   "g")
    let @e = substitute (@e, 's*$', "", "g")

    " if we end with an equal, strip, and remember for output
    if @e =~ "=$"
        let @e = substitute (@e, '=$', "", "")
        let has_equal = 1
    endif

    " if there is another equal in the line, assume chained equations, remove
    " leading ones
    let @e = substitute (@e, '^.+=', '', '')

    let answer = Calculate (@e,a:flag)

    " append answer or echo
    if has_equal == 1
        exec "normal a" . answer
    else
        echo "answer = " . answer
    endif
endfunction

原文地址:https://www.cnblogs.com/lfree/p/6994996.html