[20170611]關於數據塊地址的計算.txt--//如果資料庫出現一些問題,會在alert或者跟蹤文件,或者屏幕出現一些錯誤提示.例如:ORA-00600: internal error code, arguments: [2662], [3], [392066208], [3], [39206 ...
[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進位數據,在提示行上給出答案
\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 "<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, "\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