标签:
副标题:用一个PL/SQL查出表中的行数据存放在哪个具体的datafile中
经常有遇到做DBA的朋友问,该如何知道自己插入的某一行数据,是存在了数据库中的哪一个数据文件(datafile)上了,回答是肯定可以的。在此,就将该方法写出来供更多的朋友使用。
select rowid from tivoli.test_db_avg1 where rownum =1 |
输出值:
AAAQ0mAAEAAAAhLAAA
select dbms_rowid.rowid_relative_fno(row_id=> ‘AAAQ0mAAEAAAAhLAAA‘)from dual |
输出值:
4
select file_name from dba_data_fileswhere file_id=4 |
输出值:
/dba/oracle/oradata/single/users01.dbf
set serveroutput on DECLARE file_number INTEGER; rowid_val ROWID; file_name_val varchar2(100); BEGIN SELECT ROWID INTO rowid_val FROM tivoli.test_db_avg1 where rownum =1; file_number:= dbms_rowid.rowid_relative_fno(rowid_val); select file_name into file_name_val from dba_data_files where file_id = file_number; dbms_output.put_line(file_name_val); end; / |
输出结果:
/dba/oracle/oradata/single/users01.dbf
alter database datafile 4 offline; |
SQL> SELECT ROWID FROM tivoli.test_db_avg1 where rownum =1; SELECT ROWID FROM tivoli.test_db_avg1 where rownum =1 * ERROR at line 1: ORA-00376: file 4 cannot be read at this time ORA-01110: data file 4: ‘/dba/oracle/oradata/single/users01.dbf‘ |
已不能正常查询,说明文件定位准确。
SQL> alter database recover datafile 4; Database altered.
SQL> alter database datafile 4 online; Database altered.
SQL> SELECT ROWID FROM tivoli.test_db_avg1 where rownum =1; ROWID ------------------ AAAQ0mAAEAAAAhLAAA |
又可以正常查询到tivoli.test_db_avg1表的数据,说明按照此文的方法,完全正确的找到了具体行数据存放在哪个具体的文件上了。
标签:
原文地址:http://www.cnblogs.com/www6060bcn/p/4249293.html