oracle rowid詳解

Davis_itpub發表於2018-06-27
<div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> <span style="background-color:inherit;line-height:1.5;">oracle rowid詳解&nbsp;</span> </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> <br style="background-color:inherit;" /> </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> 本文討論的是關於oracle從8i開始引進object的概念後的rowid,即擴充套件(extended)的rowid: </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> <br style="background-color:inherit;" /> </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> <b style="background-color:inherit;">1. rowid的介紹</b> </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> <br style="background-color:inherit;" /> </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> 先對rowid有個感官認識: </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> <br style="background-color:inherit;" /> </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> SQL&gt; select ROWID from Bruce_test where rownum&lt;2; </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> <br style="background-color:inherit;" /> </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> ROWID </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> ------------------ ---------- </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> AAABnlAAFAAAAAPAAA </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> ROWID的格式如下: </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> <br style="background-color:inherit;" /> </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> 資料物件編號 &nbsp; &nbsp; &nbsp; &nbsp;檔案編號 &nbsp; &nbsp; &nbsp; &nbsp;塊編號 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 行編號 </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> OOOOOO &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; FFF &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;BBBBBB RRR </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> <br style="background-color:inherit;" /> </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> 我們可以看出,從上面的rowid可以得知: </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> AAABnl 是資料物件編號 </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> AAF是相關檔案編號 </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> AAAAAP是塊編號 </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> AAA 是行編號 </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> <br style="background-color:inherit;" /> </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> 怎麼依據這些編號得到具體的十進位制的編碼值呢,這是經常遇到的問題。這裡需要明白rowid的是基於64位編碼的18個字元顯示(資料物件編號(6) +檔案編號(3) +塊編號(6)+ &nbsp; &nbsp; &nbsp; 行編號(3)=18位),其中 </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> A-Z &lt;==&gt; 0 - 25 (26) </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> a-z &lt;==&gt; 26 - 51 (26) </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> 0-9 &lt;==&gt; 52 - 61 (10) </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> +/ &lt;==&gt; 62 - 63 (2) </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> <br style="background-color:inherit;" /> </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> 共64位,明白這個後,就可以計算出10進位制的編碼值,計算公式如下: </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> d * (b ^ p) </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> 其中:b就是基數,這裡就是64,p就是從右到左,已0開始的位置數 </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> 比如:上面的例子 </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> 檔案號AAF,具體的計算應該是: </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> 5*(64^0)=5; </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> 0*(64^1)=0; </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> 0*(64^2)=0; </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> 檔案號就是0+0+5=5 </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> 剛才提到的是rowid的顯示方式:基於64位編碼的18個字元顯示,其實rowid的儲存方式是:10 個位元組即80位儲存,其中資料物件編號需要32 位,相關檔案編號需要10 位,塊編號需要22,位行編號需要16 位,由此,我們可以得出: </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> 32bit的object number,每個資料庫最多有4G個物件 </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> 10bit的file number,每個物件最多有1022個檔案(2個檔案預留) </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> 22bit的block number,每個檔案最多有4M個BLOCK </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> 16bit的row number,每個BLOCK最多有64K個ROWS </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> <br style="background-color:inherit;" /> </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> <b style="background-color:inherit;">ROWID:</b> </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> &nbsp; &nbsp; ROWID為該錶行的唯一標識,是一個偽列,可以用在SELECT中,但不可以用INSERT, UPDATE來修改該值。 </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> 注意:ROWID的表指,普通表,cluster table, partition table, subpartition table, index, index partitions and subpartitions(注意:不包含index-organized tables). </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> &nbsp; &nbsp; 每個表Oracle都存在一個偽列ROWID,這個偽列可以用SELECT檢視,但是不可以用INSERT, UPDATE來修改。你也不可以用DELETE來刪除&nbsp;<span style="background-color:inherit;line-height:1.5;">ROWID列,Oracle使用ROWID列來建立內部索引。你可以引用ROWID的值,但ROWID並不存放在資料庫中,你可以建立一個表包含ROWID資料型別,&nbsp;</span><span style="background-color:inherit;line-height:1.5;">但Oracle不保證該值是合法的rowids。使用者必須確保該rowid值是真實合法的。&nbsp;</span> </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> <b style="background-color:inherit;">UROWID:</b> </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> &nbsp; &nbsp; UROWID(可以稱為通用ROWID,邏輯ROWID): 表的行地址,表指的是index-organized tables。IOT中物理rowid是可能變化的,另外Oracle要依靠rowid來建立表的索引,所以對IOT表來物理rowid就不行了。Oracle以表的主鍵為基礎引入UROWID,在物理rowid基礎上建立了第二個索引。每一個邏輯rowid使用一個第二索引和一個物理推測(IOT中標識塊的行)。 </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> &nbsp; &nbsp; UROWID支援邏輯和物理的rowids,列UROWID型別可以儲存各種rowids, 從8.1以後的Oracle才有UROWID型別,它也可以用來儲存以前的ROWID型別資料資訊。 </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> &nbsp; &nbsp; 更新IOT的主鍵可能導致ROWID改變,該行的UROWID也會改變。 </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> <br style="background-color:inherit;" /> </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> Oracle使用rowid資料型別儲存行地址,rowid可以分成兩種,分別適於不同的對像 : </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> Physical rowids:儲存ordinary table,clustered table,table partition and subpartition,indexe,index partition and subpartition </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> Logical rowids :儲存IOT的行地址 </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> 另一種rowid型別叫universal rowed(UROWID),支援上述physical rowid和logical rowed,並且支援非oracle table,即支援所有型別的rowid,但COMPATIBLE必須在8.1或以上. </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> <br style="background-color:inherit;" /> </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> <b style="background-color:inherit;">1.1 ROWID偽列</b> </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> &nbsp; &nbsp; 每個表在oracle內部都有一個ROWID偽列,它在所有sql中無法顯示,不佔儲存空間;它用於從表中查詢行的地址或者在where中進行參照,一個例子如下: </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> &nbsp; &nbsp; SELECT ROWID, last_name FROM employees; </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> <br style="background-color:inherit;" /> </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> &nbsp; &nbsp; Oracle內部使用保留在ROWID偽列中的值構建索引結構 </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> &nbsp; &nbsp; 再次強調一次,rowid偽列不儲存在資料庫中,它不是資料庫資料,這是從database及table的邏輯結構來說的,事實上,在物理結構上,每行由一個或多個row pieces組成,每個row piece的頭部包含了這個piece的address,即rowid.從這個意義上來說,rowid還是佔了磁碟空間的. </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> <br style="background-color:inherit;" /> </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> &nbsp; &nbsp;我們在建立表時,可以為列指定為rowid資料型別,但oracle並不保證列中的資料是合法的rowid值,必須由應用程式來保證,另外,型別為rowid的列需要6 bytes儲存資料 </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> <br style="background-color:inherit;" /> </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> <b style="background-color:inherit;">1.2, physical rowids</b> </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> 只在行存在,它的實體地址rowid就不會變化,除非export/import,根據rowid可以直接定位到block去fetch資料,所以physical兼具有高穩定(stability)和高效能(performance)的特點. </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> <br style="background-color:inherit;" /> </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> <b style="background-color:inherit;">這裡要注意一點,對於clustered table來說,根據它的儲存特點,在同一個block中的不同table的行可能具有同一個rowid;而nonclustered table,每一行或初始行片(initial row piece)都有唯一的rowid</b> </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> <br style="background-color:inherit;" /> </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> 要注意rowid的地址固定的特點,在一個block的某一行被delete並commit後,它佔據的address可以被其它事務新insert的行重用. </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> <br style="background-color:inherit;" /> </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> Physical rowid可以是下面任一一種格式: </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> &nbsp; &nbsp; 1) Extended rowid </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> &nbsp; &nbsp; &nbsp; &nbsp; 使用表空間相關的資料塊地址,8i及以上使用這種格式 </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> &nbsp; &nbsp; 2) Restricted rowid </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> &nbsp; &nbsp;使用資料庫範圍的資料址地址,oracle 7或更早前的版本使用 </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> <br style="background-color:inherit;" /> </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> <b style="background-color:inherit;">1.2.1extened rowid</b> </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> <br style="background-color:inherit;" /> </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> &nbsp; &nbsp; &nbsp; 擴充套件行地址是64編碼的實體地址,編碼字元是A-Z, a-z, 0-9, +,and/. </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> <br style="background-color:inherit;" /> </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> &nbsp; &nbsp; &nbsp; 由4部分組成OOOOOOFFFBBBBBBRRR (obj#file#block#row#) </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> <br style="background-color:inherit;" /> </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> &nbsp; &nbsp; &nbsp; OOOOOO -–data object number </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> &nbsp; &nbsp; &nbsp; &nbsp;FFF –-表空間相對的資料檔案號 </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> &nbsp; &nbsp; &nbsp; &nbsp;BBBBBB –-塊號 </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> &nbsp; &nbsp; &nbsp; &nbsp;RRR ---行號 </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> &nbsp; &nbsp; &nbsp; &nbsp;注意不是16進製表示 </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> <br style="background-color:inherit;" /> </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> &nbsp; &nbsp; &nbsp; SQL&gt; select rowid,name from obj$ where rownum&lt;=10; </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> <br style="background-color:inherit;" /> </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> ROWID &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; NAME </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> <br style="background-color:inherit;" /> </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> ------------------ ------------------------------ </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> <br style="background-color:inherit;" /> </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> AAAAASAABAAAAB6ABc ACCESS$ </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> <br style="background-color:inherit;" /> </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> AAAAASAABAAAC1QAAK AGGXMLIMP </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> <br style="background-color:inherit;" /> </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> AAAAASAABAAAC1QAAL AGGXQIMP </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> <br style="background-color:inherit;" /> </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> AAAAASAABAAAGiRAAI ALERT_QT </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> <br style="background-color:inherit;" /> </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> AAAAASAABAAAGiRAAh ALERT_QUE </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> <br style="background-color:inherit;" /> </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> AAAAASAABAAAGujAAo ALERT_QUE$1 </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> <br style="background-color:inherit;" /> </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> AAAAASAABAAAGujAAp ALERT_QUE$1 </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> <br style="background-color:inherit;" /> </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> AAAAASAABAAAGiRAAf ALERT_QUE_N </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> <br style="background-color:inherit;" /> </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> AAAAASAABAAAGiRAAe ALERT_QUE_R </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> <br style="background-color:inherit;" /> </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> AAAAASAABAAAGiRAAG ALERT_TYPE </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> <br style="background-color:inherit;" /> </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> 我們可以使用dbms_rowid從extened rowid中抽取各部分資訊,或者將extened rowid轉換成restricted rowed,詳細的資訊參見sys.dbms_rowid的規範 </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> <br style="background-color:inherit;" /> </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> #根據rowid抽塊對像編號 </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> <br style="background-color:inherit;" /> </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> SQL&gt; select dbms_rowid.rowid_object('AAAAASAABAAAGiRAAG') obj# from dual; </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> <br style="background-color:inherit;" /> </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> &nbsp; &nbsp; &nbsp;OBJ# </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> ---------- </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> &nbsp; &nbsp; &nbsp; &nbsp;18 </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> <br style="background-color:inherit;" /> </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> #根據rowid抽取表空間相對檔案號 </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> <br style="background-color:inherit;" /> </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> SQL&gt; select dbms_rowid.rowid_relative_fno('AAAAASAABAAAGiRAAG') rfile# from dual; </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> <br style="background-color:inherit;" /> </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> &nbsp; &nbsp; RFILE# </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> ---------- </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> &nbsp; &nbsp; &nbsp; &nbsp; 1 </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> <br style="background-color:inherit;" /> </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> #根據rowid抽取塊號 </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> <br style="background-color:inherit;" /> </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> SQL&gt; select dbms_rowid.ROWID_BLOCK_NUMBER('AAAAASAABAAAGiRAAG') block# from dual; </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> <br style="background-color:inherit;" /> </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> &nbsp; &nbsp;BLOCK# </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> --------- </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> &nbsp; &nbsp; 26769 </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> <br style="background-color:inherit;" /> </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> #根據rowid抽取行號 </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> <br style="background-color:inherit;" /> </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> SQL&gt; select dbms_rowid.rowid_row_number('AAAAASAABAAAGiRAAG') row# from dual; </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> <br style="background-color:inherit;" /> </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> &nbsp; &nbsp; &nbsp;ROW# </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> ---------- </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> &nbsp; &nbsp; &nbsp; &nbsp; 6 </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> <br style="background-color:inherit;" /> </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> #將extended rowid轉換成為restricted rowid </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> <br style="background-color:inherit;" /> </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> SQL&gt; select dbms_rowid.rowid_to_restricted('AAAAASAABAAAGiRAAG',0) restricted_rowid from dual; </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> <br style="background-color:inherit;" /> </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> RESTRICTED_ROWID </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> ------------------ </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> 00006891.0006.0001 </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> <br style="background-color:inherit;" /> </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> <b style="background-color:inherit;">1.2.2restricted rowid</b> </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> <br style="background-color:inherit;" /> </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> 限制地址行號與擴充套件地址行號編碼方式不一樣,它在內部使用二進位制方式表示,當用select查詢時,會轉換成varchar2/16進位制的混合形式,它的組織方式如下: </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> <br style="background-color:inherit;" /> </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> BBBBBBBB.RRRR.FFFF (block#.row#.file#) </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> <br style="background-color:inherit;" /> </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> 注意,這裡的檔案號是絕對檔案號,而extended rowid中是相對檔案號(相對錶空間) </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> <br style="background-color:inherit;" /> </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> Restricted rowid中不再有object number,因為從絕對檔案號可以唯一確定資料塊 </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> <br style="background-color:inherit;" /> </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> 樣例可以參考前面的00006891.0006.0001 </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> <br style="background-color:inherit;" /> </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> &nbsp; &nbsp; 另外請注意,塊中的行號是從0開始 </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> <br style="background-color:inherit;" /> </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> 除了用dbms_rowid來抽取rowid的不同部分外,也可以用substr </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> <br style="background-color:inherit;" /> </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> #extended rowid </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> <br style="background-color:inherit;" /> </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> SQL&gt; SELECT ROWID, </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> <br style="background-color:inherit;" /> </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> 2007-02-01 15:19:28 </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> 2 &nbsp; &nbsp; &nbsp; &nbsp; SUBSTR(ROWID,1,6) "OBJECT", </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> 3 &nbsp; &nbsp; &nbsp; &nbsp; SUBSTR(ROWID,7,3) "FIL", </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> 4 &nbsp; &nbsp; &nbsp; &nbsp; SUBSTR(ROWID,10,6) "BLOCK", </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> 5 &nbsp; &nbsp; &nbsp; &nbsp; SUBSTR(ROWID,16,3) "ROW" </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> 6 &nbsp; from obj$ where rownum&lt;=5; </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> <br style="background-color:inherit;" /> </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> ROWID &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;OBJECT &nbsp; &nbsp; &nbsp; FIL &nbsp; &nbsp;BLOCK &nbsp; &nbsp; &nbsp; &nbsp;ROW </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> ------------------ ------------ ------ ------------ ------ </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> AAAAASAABAAAAB6AAa AAAAAS &nbsp; &nbsp; &nbsp; AAB &nbsp; &nbsp;AAAAB6 &nbsp; &nbsp; &nbsp; AAa </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> AAAAASAABAAAAB6AAu AAAAAS &nbsp; &nbsp; &nbsp; AAB &nbsp; &nbsp;AAAAB6 &nbsp; &nbsp; &nbsp; AAu </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> AAAAASAABAAAAB6AAF AAAAAS &nbsp; &nbsp; &nbsp; AAB &nbsp; &nbsp;AAAAB6 &nbsp; &nbsp; &nbsp; AAF </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> AAAAASAABAAAAB6AAv AAAAAS &nbsp; &nbsp; &nbsp; AAB &nbsp; &nbsp;AAAAB6 &nbsp; &nbsp; &nbsp; AAv </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> AAAAASAABAAAAB6AAZ AAAAAS &nbsp; &nbsp; &nbsp; AAB &nbsp; &nbsp;AAAAB6 &nbsp; &nbsp; &nbsp; AAZ </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> <br style="background-color:inherit;" /> </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> #restricted rowid </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> SQL&gt; SELECT ROWID, </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> 2 &nbsp; &nbsp; &nbsp; &nbsp; SUBSTR(ROWID,15,4) "FILE", </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> 3 &nbsp; &nbsp; &nbsp; &nbsp; SUBSTR(ROWID,1,8) "BLOCK", </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> 4 &nbsp; &nbsp; &nbsp; &nbsp; SUBSTR(ROWID,10,4) "ROW" </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> 5 &nbsp; from obj$ where rownum&lt;=5; </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> <br style="background-color:inherit;" /> </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> ROWID &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;FILE &nbsp; &nbsp; BLOCK &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ROW </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> ------------------ -------- ---------------- -------- </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> AAAAASAABAAAAB6AAa 6AAa &nbsp; &nbsp; AAAAASAA &nbsp; &nbsp; &nbsp; &nbsp; AAAA </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> AAAAASAABAAAAB6AAu 6AAu &nbsp; &nbsp; AAAAASAA &nbsp; &nbsp; &nbsp; &nbsp; AAAA </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> AAAAASAABAAAAB6AAF 6AAF &nbsp; &nbsp; AAAAASAA &nbsp; &nbsp; &nbsp; &nbsp; AAAA </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> AAAAASAABAAAAB6AAv 6AAv &nbsp; &nbsp; AAAAASAA &nbsp; &nbsp; &nbsp; &nbsp; AAAA </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> AAAAASAABAAAAB6AAZ 6AAZ &nbsp; &nbsp; AAAAASAA &nbsp; &nbsp; &nbsp; &nbsp; AAAA </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> <br style="background-color:inherit;" /> </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> 請注意extented rowid與restricted rowid的編碼方式不一樣,大家不能拿兩種不同編碼方式的元件作比較,比如AAAAASAABAAAAB6AAa 這行的File#在兩種方式下是有不同的值,表示不同的意義,沒有可比性. </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> <br style="background-color:inherit;" /> </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> 下面的語句可以檢視錶的資料分佈在幾個檔案中 </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> SQL&gt; SELECT COUNT(DISTINCT(SUBSTR(ROWID,7,3))) "FILES" FROM BOSSSTATSDATA; </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> <br style="background-color:inherit;" /> </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> &nbsp; &nbsp; &nbsp;FILES </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> ---------- </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> &nbsp; &nbsp; &nbsp; &nbsp; 17 </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> #下面驗證bossstatsdata的資料確實分佈在17個檔案中 </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> SQL&gt; select count(file_name) from dba_data_files where TABLESPACE_NAME= (select TABLESPACE_NAME from user_tables where table_name='BOSSSTATSDATA'); </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> <br style="background-color:inherit;" /> </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> COUNT(FILE_NAME) </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> ---------------- </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 17 </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> <br style="background-color:inherit;" /> </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> 總結Rowid的使用場景 </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> 1) 構建索引結構, 每個key都有一個rowid指向相應的錶行 </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> 2) rowid是訪問錶行的最快的方法 </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> 3) rowid可用於觀察表資料是怎樣組織的 </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> 4) rowid是錶行的唯一識別符號 </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> <br style="background-color:inherit;" /> </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> 在任何DML中使用rowid時,應該注意確保相關的行不會改變實體地址(不會被export/import,delete) </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> <br style="background-color:inherit;" /> </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> <b style="background-color:inherit;">1.3 logical rowids</b> </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> &nbsp; &nbsp; 用於表達IOT行地址的Logical rowid儲存在索引的葉子節點中,會隨著索引entry的insert在塊內或塊間移動,所以,它不是基於實體地址而是基於primary key的識別符號,所以取名叫logcial rowid </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> Oracle使用logical rowids來構建IOT的secondary indexes </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> 由於在實際的應用中很少會使用到IOT這種對像,關於logical rowid更詳細的描述可以參見&lt;&lt;concepts&gt;&gt;中相關章節 </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> Part IV Oracle Database Application Development </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> 26 Native Datatypes </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> Overview of ROWID and UROWID Datatypes </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> <br style="background-color:inherit;" /> </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> <b style="background-color:inherit;">1.4 非oracle table中的rowid</b> </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> 在非oracle系統中,不同的系統有不同的rowid格式,並且,不能使用前述標準的rowid到varchar2/16進位制的轉換方法, 所以,在這種情況下,應用程式可以使用rowid資料型別,不過要使用非標準的轉換方法 (最長256bytes的16進位制) </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> 非oracle 系統中的rowid也能儲存在UROWID資料型別中 </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> <br style="background-color:inherit;" /> </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> <br style="background-color:inherit;" /> </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> <div> <b style="background-color:inherit;">3. rowid相關的有用的sql</b> </div> <div> <b style="background-color:inherit;">3.1最簡單的基於rowid的顯示方式得到的響應的64位編碼對應值的sql:</b> </div> <div> select rowid , </div> <div> substr(rowid,1,6) "OBJECT", </div> <div> substr(rowid,7,3) "FILE", </div> <div> substr(rowid,10,6) "BLOCK", </div> <div> substr(rowid,16,3) "ROW" </div> <div> from TableName; </div> <div> <br style="background-color:inherit;" /> </div> <div> OWID &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;OBJECT &nbsp; &nbsp; &nbsp; FILE &nbsp; BLOCK &nbsp; &nbsp; &nbsp; &nbsp;ROW </div> <div> ------------------ ------------ ------ ------------ ------ </div> <div> AAABc4AADAAAGLUAAA AAABc4 &nbsp; &nbsp; &nbsp; AAD &nbsp; &nbsp;AAAGLU &nbsp; &nbsp; &nbsp; AAA </div> <div> AAABc4AADAAAGLUAAB AAABc4 &nbsp; &nbsp; &nbsp; AAD &nbsp; &nbsp;AAAGLU &nbsp; &nbsp; &nbsp; AAB </div> <div> AAABc4AADAAAGLUAAC AAABc4 &nbsp; &nbsp; &nbsp; AAD &nbsp; &nbsp;AAAGLU &nbsp; &nbsp; &nbsp; AAC </div> <div> AAABc4AADAAAGLUAAD AAABc4 &nbsp; &nbsp; &nbsp; AAD &nbsp; &nbsp;AAAGLU &nbsp; &nbsp; &nbsp; AAD </div> <div> AAABc4AADAAAGLUAAE AAABc4 &nbsp; &nbsp; &nbsp; AAD &nbsp; &nbsp;AAAGLU &nbsp; &nbsp; &nbsp; AAE </div> <div> <br style="background-color:inherit;" /> </div> <div> <b style="background-color:inherit;">3.2透過dbms_rowid這個包,可以直接的得到具體的rowid包含的資訊:</b> </div> <div> select dbms_rowid.rowid_object(rowid) object_id, dbms_rowid.rowid_relative_fno(rowid) file_id, </div> <div> dbms_rowid.rowid_block_number(rowid) block_id ,dbms_rowid.rowid_row_number(rowid) num from bruce_t where rownum&lt;5; </div> <div> <br style="background-color:inherit;" /> </div> <div> OBJECT_ID &nbsp; &nbsp;FILE_ID &nbsp; BLOCK_ID &nbsp; &nbsp; &nbsp; &nbsp;NUM </div> <div> ---------- ---------- ---------- ---------- </div> <div> &nbsp; &nbsp; &nbsp; 5944 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;3 &nbsp; &nbsp; &nbsp;25300 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;0 </div> <div> &nbsp; &nbsp; &nbsp; 5944 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;3 &nbsp; &nbsp; &nbsp;25300 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;1 </div> <div> &nbsp; &nbsp; &nbsp; 5944 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;3 &nbsp; &nbsp; &nbsp;25300 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;2 </div> <div> &nbsp; &nbsp; &nbsp; 5944 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;3 &nbsp; &nbsp; &nbsp;25300 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;3 </div> <div> <br style="background-color:inherit;" /> </div> <div> <b style="background-color:inherit;">3.3一些使用ROWID的函式</b> </div> <div> ROWIDTOCHAR(rowid) :將ROWID轉換成STRING </div> <div> CHARTOROWID('rowid_string') :將STRING轉換成ROWID </div> <div> <br style="background-color:inherit;" /> </div> <div> 另外,就是自己寫的一些函式:(下面的函式由eygle提供) </div> <div> <br style="background-color:inherit;" /> </div> <div> create or replace function get_rowid </div> <div> <br style="background-color:inherit;" /> </div> <div> (l_rowid in varchar2) </div> <div> return varchar2 </div> <div> is </div> <div> ls_my_rowid &nbsp; &nbsp; varchar2(200); &nbsp; &nbsp; &nbsp; &nbsp; </div> <div> rowid_type &nbsp; &nbsp; number; &nbsp; &nbsp; &nbsp; &nbsp; </div> <div> object_number &nbsp; &nbsp; number; &nbsp; &nbsp; &nbsp; &nbsp; </div> <div> relative_fno &nbsp; &nbsp; number; &nbsp; &nbsp; &nbsp; &nbsp; </div> <div> block_number &nbsp; &nbsp; number; &nbsp; &nbsp; &nbsp; &nbsp; </div> <div> row_number &nbsp; &nbsp; number; </div> <div> <br style="background-color:inherit;" /> </div> <div> begin </div> <div> dbms_rowid.rowid_info(l_rowid,rowid_type,object_number,relative_fno, block_number, row_number); &nbsp; &nbsp; &nbsp; &nbsp; </div> <div> ls_my_rowid := 'Object# is &nbsp; &nbsp; &nbsp;:'||to_char(object_number)||chr(10)|| </div> <div> &nbsp; &nbsp; &nbsp; &nbsp; 'Relative_fno is :'||to_char(relative_fno)||chr(10)|| </div> <div> &nbsp; &nbsp; &nbsp; &nbsp; 'Block number is :'||to_char(block_number)||chr(10)|| </div> <div> &nbsp; &nbsp; &nbsp; &nbsp; 'Row number is &nbsp; :'||to_char(row_number); </div> <div> return ls_my_rowid ; </div> <div> end; &nbsp; &nbsp; &nbsp; &nbsp; </div> <div> <br style="background-color:inherit;" /> </div> <div> / </div> <div> <br style="background-color:inherit;" /> </div> <div> 應用上面的函式如下: </div> <div> SQL&gt; select get_rowid(rowid), name from bruce_t; </div> <div> GET_ROWID(ROWID) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; NAME </div> <div> <br style="background-color:inherit;" /> </div> <div> -------------------------------------------------------------------------------- -------------------------------- </div> <div> Object# is &nbsp; &nbsp; &nbsp;:5944 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;BruceLau </div> <div> Relative_fno is :3 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </div> <div> Block number is :25300 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </div> <div> Row number is &nbsp; :0 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </div> <div> Object# is &nbsp; &nbsp; &nbsp;:5944 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; MabelTang </div> <div> Relative_fno is :3 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </div> <div> Block number is :25300 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </div> <div> Row number is &nbsp; :1 </div> <div> <br style="background-color:inherit;" /> </div> <div> <b style="background-color:inherit;">3.4 查詢rowid時要注意的地方,必須包括rowid=1:</b><br style="background-color:inherit;" /> </div> <div> <div> select * from tablename where rowid=1; </div> <div> no rows returned </div> <div> <br style="background-color:inherit;" /> </div> <div> select * from tablename where rowid&gt;=1; </div> <div> ID &nbsp; &nbsp; NAME </div> <div> 1 &nbsp; &nbsp; &nbsp; &nbsp;aa </div> <div> 2 &nbsp; &nbsp; &nbsp; &nbsp;abcd </div> <div> <br style="background-color:inherit;" /> </div> <div> select * from tablename where rowid&lt;3; </div> <div> <div> ID &nbsp; &nbsp; NAME </div> <div> 1 &nbsp; &nbsp; &nbsp; &nbsp;aa </div> <div> 2 &nbsp; &nbsp; &nbsp; &nbsp;abcd </div> </div> </div> <br style="background-color:inherit;" /> </div> <div style="font-family:微軟雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> &nbsp; </div>

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

相關文章