bbed获取oracle dbid(oracle十进制和十六进制转换)

来源:互联网 发布:c语言break跳出if 编辑:程序博客网 时间:2024/06/07 13:23

SQL> select DBID,NAME from v$database;                                                                                                                                          

      DBID NAME
---------- ---------
1408025210 DUXIU

 

SQL> select dump('DUXIU',16) from dual;            -------------数据库名转换城16进制                                                                                                                             

DUMP('DUXIU',16)
----------------------------
Typ=96 Len=5: 44,55,58,49,55

SQL> select to_char(1408025210,'xxxxxxxxxxxx') from dual;        ----- -- ----dbid转换成16进制                                                                                                            

TO_CHAR(14080
-------------
     53ecc27a

[oracle@stu50 ~]$ bbed
Password:

BBED: Release 2.0.0.0.0 - Limited Production on Thu May 2 14:57:26 2013

Copyright (c) 1982, 2005, Oracle.  All rights reserved.

************* !!! For Oracle Internal Use only !!! ***************

BBED> set filename '/opt/oracle/oradata/duxiu/system01.dbf'
        FILENAME        /opt/oracle/oradata/duxiu/system01.dbf

BBED> set block 1
        BLOCK#          1

BBED> dump /v count 100
 File: /opt/oracle/oradata/duxiu/system01.dbf (0)
 Block: 1       Offsets:    0 to   99  Dba:0x00000000
-------------------------------------------------------
 0ba20000 01004000 00000000 00000104 l ......@.........
 c5be0000 00000000 0001200a 7ac2ec53 l .......... .z..S        4个字节为dbid 就是上面的值(53  ec   c2  7a)
 44555849 55000000 31040000 00f50000 lDUXIU...1.......  8个字节数据库名,也是数据库名最大8个字节的原因
 00200000 01000300 00000000 00000000 l . ..............
 00000000 00000000 00000000 00000000 l ................
 00000000 00000000 00000000 00000000 l ................
 79014000                            l y.@.

 <16 bytes per line>

 

BBED> set offset 32
        OFFSET          32

BBED> dump count 8
 File: /opt/oracle/oradata/duxiu/system01.dbf (0)
 Block: 1                Offsets:   32 to   39           Dba:0x00000000
------------------------------------------------------------------------
 44555849 55000000

 <32 bytes per line>

BBED> set offset 28
        OFFSET          28

BBED> dump count 4
 File: /opt/oracle/oradata/duxiu/system01.dbf (0)
 Block: 1                Offsets:   28 to   31           Dba:0x00000000
------------------------------------------------------------------------
 7ac2ec53

 <32 bytes per line>

BBED>

总结:数据文件第一个数据块的offset 32-39为dbname(8个字节),offset28-31为dbid(4个字节)

SQL> select to_number('53ecc27a','xxxxxxxxxx') from dual;                                                                                                                       

TO_NUMBER('53ECC27A','XXXXXXXXXX')
----------------------------------
                        1408025210

 

SQL> select utl_raw.cast_to_varchar2(replace('44,55,58,49,55',',','')) dbname from dual;       

DBNAME
--------------------------------------------------------------------------------
DUXIU

 

---------------------------------------------------------------

utl_raw这函数给力

SQL> select dump(175185,16) from dual;                                                         

DUMP(175185,16)
------------------------
Typ=2 Len=4: c3,12,34,56

SQL> select utl_raw.cast_to_number(replace('c3,12,34,56',',','')) num from dual;               

       NUM
----------
    175185

SQL>

 使用oracle utl_raw作为dump的逆函数

原创粉丝点击