1、表的概念
表是数据库数据存储的基本单元,它 对应现实世界的对象。
2、表的功能
存储、管理数据的基本单元(二维表:有行和列组成)
3、表的类型
普通表:数据以无序的方式存储在单独的表段里。
簇表: 簇由共享相同数据块的一组表组成。
索引表:数据以B-树机构存放在主键约束所对应的索引段里。
分区表:数据被划分为更小的部分,并且存储到相应的分区段里,每个分区段可以独立管理和操作。
4、ROWID
ROWID 是表的伪列,它拥有唯一标识表行。ROWID间接给出了表行的物理位置,它是定位表行最快的方式。
使用Insert语句插入数据时,Oracle会自动生成ROWID,并将其值与表数据一起存放到表行里。
5、分析ROWID
extended rowid: object id (6),relative file id(3),block id (6),row id(3)
(1)对比普通表和簇表的rowid
SQL> select rowid,ename,sal from scott.emp;
ROWID ENAME SAL
------------------ ---------- ----------
AAACYNAAEAAAAAeAAA SMITH 800
AAACYNAAEAAAAAeAAB ALLEN 1600
AAACYNAAEAAAAAeAAC WARD 1250
AAACYNAAEAAAAAeAAD JONES 2975
AAACYNAAEAAAAAeAAE MARTIN 1250
AAACYNAAEAAAAAeAAF BLAKE 2850
AAACYNAAEAAAAAeAAG CLARK 2450
AAACYNAAEAAAAAeAAH SCOTT 6000
AAACYNAAEAAAAAeAAI KING 5000
AAACYNAAEAAAAAeAAJ TURNER 1500
AAACYNAAEAAAAAeAAK ADAMS 1100
AAACYNAAEAAAAAeAAL JAMES 950
AAACYNAAEAAAAAeAAM FORD 3000
AAACYNAAEAAAAAeAAN MILLER 1300
SQL> select rowid,deptno,dname from scott.dept;
ROWID DEPTNO DNAME
------------------ ---------- ---------------
AAACYLAAEAAAAAOAAA 10 ACCOUNTING
AAACYLAAEAAAAAOAAB 20 RESEARCH
AAACYLAAEAAAAAOAAC 30 SALES
AAACYLAAEAAAAAOAAD 40 OPERATIONS
SQL> select rowid,ename,sal from employee;
ROWID ENAME SAL
------------------ ---------- ----------
AAACaEAAGAAAAEZAAA SMITH 800
AAACaEAAGAAAAEZAAB ALLEN 1600
AAACaEAAGAAAAEZAAC WARD 1250
AAACaEAAGAAAAEZAAD JONES 2975
AAACaEAAGAAAAEZAAE MARTIN 1250
AAACaEAAGAAAAEZAAF BLAKE 2850
AAACaEAAGAAAAEZAAG CLARK 2450
AAACaEAAGAAAAEZAAH SCOTT 6000
AAACaEAAGAAAAEZAAI KING 5000
AAACaEAAGAAAAEZAAJ TURNER 1500
AAACaEAAGAAAAEZAAK ADAMS 1100
AAACaEAAGAAAAEZAAL JAMES 950
AAACaEAAGAAAAEZAAM FORD 3000
AAACaEAAGAAAAEZAAN MILLER 1300
SQL> select rowid,id,dname from department;
ROWID ID DNAME
------------------ ---------- ---------------
AAACaEAAGAAAAEZAAA 10 ACCOUNTING
AAACaEAAGAAAAEZAAB 20 RESEARCH
AAACaEAAGAAAAEZAAC 30 SALES
AAACaEAAGAAAAEZAAD 40 OPERATIONS
――结论:在建立cluster的表,通过rowid,可以看到不同的表的记录放在了相同的block 上
(2)将rowid转换成十进制形式
SQL>set serverout on
SQL>
DECLARE v_rowid_type NUMBER;
v_OBJECT_NUMBER NUMBER;
v_RELATIVE_FNO NUMBER;
v_BLOCK_NUMBERE_FNO NUMBER;
v_ROW_NUMBER NUMBER;
BEGIN
DBMS_ROWID.rowid_info(rowid_in=>'&num',
rowid_type =>v_rowid_type,
object_number =>v_OBJECT_NUMBER,
relative_fno =>v_RELATIVE_FNO,
block_number =>v_BLOCK_NUMBERE_FNO,
ROW_NUMBER =>v_ROW_NUMBER);
DBMS_OUTPUT.put_line('ROWID_TYPE:' ||TO_CHAR(v_rowid_type));
DBMS_OUTPUT.put_line('OBJECT_NUMBER:' ||TO_CHAR(v_OBJECT_NUMBER));
DBMS_OUTPUT.put_line('RELATIVE_FNO:' ||TO_CHAR(v_RELATIVE_FNO));
DBMS_OUTPUT.put_line('BLOCK_NUMBER:' ||TO_CHAR(v_BLOCK_NUMBERE_FNO));
DBMS_OUTPUT.put_line('ROW_NUMBER:' ||TO_CHAR(v_ROW_NUMBER));
END;
/
Enter value for num: AAACYNAAEAAAAAeAAH
old 6: DBMS_ROWID.rowid_info(rowid_in=>'&num',
new 6: DBMS_ROWID.rowid_info(rowid_in=>'AAACYNAAEAAAAAeAAH',
ROWID_TYPE:1
OBJECT_NUMBER:9741
RELATIVE_FNO:4
BLOCK_NUMBER:30
ROW_NUMBER:7
PL/SQL procedure successfully completed.
SQL> select object_name,object_id,object_type,status from user_objects
2 where object_name='EMP';
OBJECT_NAME OBJECT_ID OBJECT_TYPE STATUS
--------------- ---------- --------------- ---------------------
EMP 9741 TABLE VALID
SQL> conn /as sysdba
SQL> COL SEGMENT_NAME FOR A30
SQL> select segment_name,tablespace_name,file_id,block_id from dba_extents
2 where segment_name='EMP';
SEGMENT_NAME TABLESPACE_NAME FILE_ID BLOCK_ID
--------------- --------------- ---------- ----------
EMP USERS 4 25
SQL> select segment_name,tablespace_name,file_id,block_id,EXTENT_ID,BYTES/1024 from dba_extents
2 where segment_name='EMP';
SEGMENT_NAME TABLESPACE_NAME FILE_ID BLOCK_ID EXTENT_ID BYTES/1024
--------------- --------------- ---------- ---------- ---------- ----------
EMP USERS 4 25 0 64
更多oracle视频教程请点击:http://crm2.qq.com/page/portalpage/wpa.php?uin=800060152&f=1&ty=1&aty=0&a=&from=6