【oracle】rowid轉換rdba,rdba轉換為file#block#,

來源:互聯網
上載者:User

【oracle】rowid轉換rdba,rdba轉換為file#block#,
************************************************************************  ****原文:blog.csdn.net/clark_xu 徐長亮的專欄************************************************************************ -- 1 rowid和rdba的轉換


      --資料的儲存屬性rowid
             --資料檔案file#
             --資料庫物件obj#
             --資料區塊號:block_no#
             --表中行號
       --物理rowid和邏輯rowid
             --索引使用邏輯rowid
             --其他類型使用物理rowid
       --rowid偽列
       select rowid,id,time from rangetable; 
       --因為rowid唯一標示一條記錄,所以索引儲存rowid值;通過索引中,找到rowid;
       --新的base64編碼。32bit obj#,10bit rfile#,22bit block#,16bit row#
         --因此每個資料表空間最大1022個檔案,每個資料檔案最大4M=4000個block
         --每個block中的行數最大65536行;
      --通過dbms_rowid來轉換rowid的資訊
      create or replace function get_rowid(l_rowid in varchar2)
      return varchar2
      is
      ls_my_rowid varchar2(200);
      rowid_type number;
      object_number number;
      relative_fno number;
      block_number number;
      row_number number;
      begin
           dbms_rowid.rowid_info(l_rowid,rowid_type,object_number,relative_fno,block_number,row_number);
          
           ls_my_rowid:='Object# is :'
           ||to_char(object_number)||chr(10)||
           'relative_fno is :'
           ||to_char(relative_fno)||chr(10)||
           'block_number is :'
           ||to_char(block_number)||chr(10)||
           'row number is :'
           ||to_char(row_number)||chr(10);
          
           return ls_my_rowid;
      end;
     
      select rowid,a.* from dept a;
      select get_rowid('AAAMfNAAEAAAAAQAAA') row_id from dual;

2 RDBA轉換為file#,block#

--轉儲system的資料表空間
   alter session set events 'immediate trace name FILE_HDRS level 10'
   --查看udummp檔案dba地址
   寫了一個簡單的函數,用來從RDBA中轉換file#和block#出來:


CREATE OR REPLACE FUNCTION getbfno (p_dba IN VARCHAR2)
   RETURN VARCHAR2
IS
   l_str   VARCHAR2 (255) DEFAULT NULL;
   l_fno   VARCHAR2 (15);
   l_bno   VARCHAR2 (15);
BEGIN
   l_fno :=
      DBMS_UTILITY.data_block_address_file (TO_NUMBER(LTRIM (p_dba, '0x'), 'xxxxxxxx'));
   l_bno :=
      DBMS_UTILITY.data_block_address_block (TO_NUMBER (LTRIM (p_dba, '0x'), 'xxxxxxxx'));
   l_str :=
         'datafile# is:'
      || l_fno
      || CHR (10)
      || 'datablock is:'
      || l_bno
      || CHR (10)
      || 'dump command:alter system dump datafile '
      || l_fno
      || ' block '
      || l_bno
      || ';';
   RETURN l_str;
END;
   select getbfno('0x00400179') bfno from dual;

************************************************************************  ****原文:blog.csdn.net/clark_xu 徐長亮的專欄************************************************************************  


相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.