[20170611]關於資料塊地址的計算.txt

lfree發表於2017-06-12

[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/
--//原始碼我修改加入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進位制資料,在提示行上給出答案

\bx 可以進行行運算
\bc 在提示行輸出結果.

;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 " = " . Calculate ("")

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

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


"nnoremap  bc "eyy$:callCalcBC(0)

"" calculate from insertmode
inoremap =: = "eyy:call CalcLines()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, "\n",   "", "g")
    let str = substitute (str, '\s*$', "", "g")

    " sub common func names for bc equivalent
    let str = substitute (str, '\csin\s*(',  's (', 'g')
    let str = substitute (str, '\ccos\s*(',  'c (', 'g')
    let str = substitute (str, '\catan\s*(', 'a (', 'g')
    let str = substitute (str, "\cln\s*(",   'l (', 'g')
    let str = substitute (str, '\clog\s*(',  'l (', 'g')
    let str = substitute (str, '\cexp\s*(',  '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, "\n", "", "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, "\n", "",   "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

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

相關文章