创建表空间:
SQL> CREATE TABLESPACE testts DATAFILE'/u01/app/oracle/oradata/jiagulun/testts1'
2 SIZE 10M AUTOEXTEND ON;
Tablespace created
SQL> select * from v$datafile;//查询数据文件
SQL> SELECT * FROM DBA_TABLES dt where dt.table_name='TEST2';//查询某个表的详细信息、段区块等
SQL> select * from user_extents ue where ue.tablespace_name='TESTTS';
SEGMENT_NAME PARTITION_NAME SEGMENT_TYPE TABLESPACE_NAME EXTENT_ID BYTES BLOCKS
-------------------------------------------------------------------------------- ------------------------------ ------------------ ------------------------------ ---------- ---------- ----------
SQL> create table test3 (id number(10),name varchar2(20)) tablespace testts;
Table created//创建表以后才在为表空间分配存储区域
SQL> select * from user_extents ue where ue.tablespace_name='TESTTS';
SEGMENT_NAME PARTITION_NAME SEGMENT_TYPE TABLESPACE_NAME EXTENT_ID BYTES BLOCKS
-------------------------------------------------------------------------------- ------------------------------ ------------------ ------------------------------ ---------- ---------- ----------
TEST3 TABLE TESTTS 0 65536 8
SQL> alter table sys.test3 allocate extent(datafile '/u01/app/oracle/oradata/jiagulun/testts1' size 1m);
Table altered//扩展某个表的大小
SQL> select * from user_extents ue where ue.tablespace_name='TESTTS';
SEGMENT_NAME PARTITION_NAME SEGMENT_TYPE TABLESPACE_NAME EXTENT_ID BYTES BLOCKS
-------------------------------------------------------------------------------- ------------------------------ ------------------ ------------------------------ ---------- ---------- ----------
TEST3 TABLE TESTTS 0 65536 8
.... . ... . ....
TEST3 TABLE TESTTS 13 65536 8
TEST3 TABLE TESTTS 14 65536 8
TEST3 TABLE TESTTS 15 65536 8
TEST3 TABLE TESTTS 16 1048576 128
17 rows selected
SQL>
|
2,移动表move,从一个表空间移动到另一个表空间,可以清楚表里的碎片
alter table t1 move [tablespace users];
优点:清除数据块中的碎片,降低HWM
缺点:move过程中,表上不能有应用。
SQL> select max(rownum) from user_objects;
MAX(ROWNUM)
-----------
38
SQL> create table test1 tablespace testts as select * from user_objects;
Table created
SQL> select ut.TABLE_NAME,ut.BLOCKS,ut.TABLESPACE_NAME,ut.NUM_ROWS from user_tables ut where ut.TABLE_NAME='TEST1';
TABLE_NAME BLOCKS TABLESPACE_NAME NUM_ROWS
------------------------------ ---------- ------------------------------ ----------
SQL> analyze table test1 compute statistics for table;//分析表
Table analyzed
SQL> select ut.TABLE_NAME,ut.BLOCKS,ut.TABLESPACE_NAME,ut.NUM_ROWS from user_tables ut where ut.TABLE_NAME='TEST1';
TABLE_NAME BLOCKS TABLESPACE_NAME NUM_ROWS
------------------------------ ---------- ------------------------------ ----------
TEST1
4 TESTTS 39
SQL> delete from test1;
39 rows deleted
SQL> commit;
Commit complete
SQL> analyze table test1 compute statistics for table;
Table analyzed
SQL> select ut.TABLE_NAME,ut.BLOCKS,ut.TABLESPACE_NAME,ut.NUM_ROWS from user_tables ut where ut.TABLE_NAME='TEST1';
TABLE_NAME
BLOCKS TABLESPACE_NAME NUM_ROWS
------------------------------ ---------- ------------------------------ ----------
TEST1
4 TESTTS 0
SQL>
alter table test1 move;//清除碎片
Table altered
SQL> select ut.TABLE_NAME,ut.BLOCKS,ut.TABLESPACE_NAME,ut.NUM_ROWS from user_tables ut where ut.TABLE_NAME='TEST1';
TABLE_NAME BLOCKS TABLESPACE_NAME NUM_ROWS
------------------------------ ---------- ------------------------------ ----------
TEST1 4 TESTTS 0
SQL> commit;
Commit complete
SQL> analyze table test1 compute statistics for table;
Table analyzed
SQL> select ut.TABLE_NAME,ut.BLOCKS,ut.TABLESPACE_NAME,ut.NUM_ROWS from user_tables ut where ut.TABLE_NAME='TEST1';
TABLE_NAME BLOCKS TABLESPACE_NAME NUM_ROWS
------------------------------ ---------- ------------------------------ ----------
TEST1
0 TESTTS 0
SQL>
通过上面的move方式可以清除碎片,高水位线可以到达数据块占用的位置处
|
3,收缩表shrink,将数据行从一个数据块移动到另一个数据
块,分为2个阶段:收缩、降低HWM;在收缩阶段,可以对
表进行DML操作,在降低HWM阶段,不能对表进行DML操
作。
alter table t2 shrink space [cascade];
前提:表所在的表空间使用了ASSM。
表上启用了 row movement
SQL> select * from tab t where t.tname='TEST1';
TNAME TABTYPE CLUSTERID
------------------------------ ------- ----------
TEST1 TABLE
SQL> select UT.TABLE_NAME,ut.TABLESPACE_NAME,ut.NUM_ROWS from user_tables ut where ut.TABLE_NAME='TEST1';
TABLE_NAME TABLESPACE_NAME NUM_ROWS
------------------------------ ------------------------------ ----------
TEST1 TESTTS 0
SQL> select UT.TABLE_NAME,ut.TABLESPACE_NAME,ut.BLOCKS,ut.NUM_ROWS from user_tables ut where ut.TABLE_NAME='TEST1';
TABLE_NAME TABLESPACE_NAME BLOCKS NUM_ROWS
------------------------------ ------------------------------ ---------- ----------
TEST1 TESTTS 0 0
SQL> insert into test1 select * from user_objects;
39 rows inserted
SQL> analyze table test1 compute statistics for table;
Table analyzed
SQL> select UT.TABLE_NAME,ut.TABLESPACE_NAME,ut.BLOCKS,ut.NUM_ROWS from user_tables ut where ut.TABLE_NAME='TEST1';
TABLE_NAME TABLESPACE_NAME BLOCKS NUM_ROWS
------------------------------ ------------------------------ ---------- ----------
TEST1 TESTTS 5 39
SQL> delete from test1 where rownum <20;
19 rows deleted
SQL> analyze table test1 compute statistics for table;
Table analyzed
SQL> select UT.TABLE_NAME,ut.TABLESPACE_NAME,ut.BLOCKS,ut.NUM_ROWS from user_tables ut where ut.TABLE_NAME='TEST1';
TABLE_NAME TABLESPACE_NAME BLOCKS NUM_ROWS
------------------------------ ------------------------------ ---------- ----------
TEST1 TESTTS 5 20
SQL> alter table test1 shrink space;
alter table test1 shrink space
ORA-10636: ROW MOVEMENT is not enabled
SQL> alter table test1 enable row movement ;
Table altered
SQL> alter table test1 shrink space
2 ;
Table altered
SQL> select UT.TABLE_NAME,ut.TABLESPACE_NAME,ut.BLOCKS,ut.NUM_ROWS from user_tables ut where ut.TABLE_NAME='TEST1';
TABLE_NAME TABLESPACE_NAME BLOCKS NUM_ROWS
------------------------------ ------------------------------ ---------- ----------
TEST1 TESTTS 5 20
SQL> analyze table test1 compute statistics for table;
Table analyzed
SQL> select UT.TABLE_NAME,ut.TABLESPACE_NAME,ut.BLOCKS,ut.NUM_ROWS from user_tables ut where ut.TABLE_NAME='TEST1';
TABLE_NAME TABLESPACE_NAME BLOCKS NUM_ROWS
------------------------------ ------------------------------ ---------- ----------
TEST1 TESTTS 1 20
SQL>
|
4,截断表truncate,将表中的记录全部删除,保留表的结构。释放表所占用的全部数据块,并把HWM调整到最低,而且不能回滚。
5,删除表drop
drop table t2 [cascade constraints] [purge];
alter table t2 set unused column tele;
alter table t2 drop unused columns
//1. 删除某列信息,没有使用alter unused方式
SQL> desc test1;
Name Type Nullable Default Comments
-------------- ------------- -------- ------- --------
OBJECT_NAME VARCHAR2(128) Y
SUBOBJECT_NAME VARCHAR2(30) Y
OBJECT_ID NUMBER Y
DATA_OBJECT_ID NUMBER Y
OBJECT_TYPE VARCHAR2(19) Y
CREATED DATE Y
LAST_DDL_TIME DATE Y
TIMESTAMP VARCHAR2(19) Y
STATUS VARCHAR2(7) Y
TEMPORARY VARCHAR2(1) Y
GENERATED VARCHAR2(1) Y
SECONDARY VARCHAR2(1) Y
NAMESPACE NUMBER Y
EDITION_NAME VARCHAR2(30) Y
SQL> alter table test1 drop column object_id;
Table altered
花费了5.063秒
SQL> commit;
Commit complete
//2. 删除某列信息,使用alter unused方式
SQL> alter table test1 set unused column object_name;
Table altered
花费0.031秒
SQL> alter table test1 drop unused column;
Table altered花费4.75秒;所以总共花费了4.781秒比上面的要节省0.282秒
SQL>
SQL>
|
1,区别于普通表的无序组织方式,IOT(Index Organized
Table)表必须有主键,是有序的表,其中的数据按照主键进
行存储和排序。
2,使用堆组织表时,我们必须为表和表主键上的索引分别留
出空间。而IOT不存在主键的空间开销,因为IOT的数据存储
在与其关联的索引中,索引就是数据,数据就是索引,二者
已经合二为一。
3,IOT表中,表的数据存放在索引块中,所以如果通过主键
索引访问表时,只需要读取一个块即可。而如果通过主键索
引访问普通表,至少需要读取两个块,一个是索引块、一个
是数据块。
4,对于经常通过主键访问数据的表来说,适合使用IOT表。
create table iot_student(
sno int,
sname varchar2(100),
sage int, constraint pk_student primary key(sno))
organization index
[ pctthreshold 30 overflow tablespace users ];
因为所有数据都放入索引,所以当表的数据量很大时,会
降低索引组织表的查询性能。此时设置溢出段将主键和溢出
数据分开来存储以提高效率。
说明: pctthreshold制定一个数据块的百分比,当行数据
占用大小超出时,该行的其他列数据放入溢出段,即
overflow指定存储空间中去,所以pctthreshold是保留在索引
块里的数据量占整个索引块的大小百分比,从0到50%。
SQL> create table test1 (id number(10),name varchar2(20),address varchar2(20), constraints pk_test1 primary key(id))
2 organization index pctthreshold 30 overflow tablespace users;
Table created
SQL> select * from tab t where t.tname like '%SYS%';
TNAME TABTYPE CLUSTERID
------------------------------ ------- ----------
SYS_IOT_OVER_75124 TABLE//这个表就是溢出段所存放的表
SQL> select uic.TABLE_NAME,uic.COLUMN_NAME,uic.INDEX_NAME from user_ind_columns uic where uic.TABLE_NAME='TEST1';
TABLE_NAME COLUMN_NAME INDEX_NAME
------------------------------ -------------------------------------------------------------------------------- ------------------------------
TEST1 ID PK_TEST1
SQL> drop index pk_test1;
drop index pk_test1
ORA-02429: 无法删除用于强制唯一/主键的索引
SQL> alter table test1 drop primary key;
alter table test1 drop primary key
ORA-25188: 对于索引表或排序散列簇, 无法删除/禁用/延迟主键约束条件
SQL> drop table test1;
Table dropped
SQL> select * from tab t where t.tname like '%SYS%';
TNAME TABTYPE CLUSTERID
------------------------------ ------- ----------
SYS_IOT_OVER_75124 TABLE
假如在此处删除是删除不了的,只能通过下面的方式达到
SQL> purge recyclebin;
Done
SQL> select * from tab t where t.tname like '%SYS%';
TNAME TABTYPE CLUSTERID
------------------------------ ------- ----------
SQL>
|
两个相互关联的表的数据,同时放到一个簇数据块中,当
以后进行关联读取时,只需要扫描一个数据块就可以了,极
大的提高了效率。
分为索引簇表和哈希簇表两类。
索引簇表的创建步骤:
1,建立簇段cluster segment
2,基于簇,创建两个相关表,每个表都关联到cluster segment上。
3,为簇创建索引。
create cluster scott.cluster1(code_key number);
create table scott.student (sno1 number, sname varchar2(10)) cluster scott.cluster1(sno1);
create table scott.address (sno2 number, zz varchar2(10)) cluster scott.cluster1(sno2);
create index index1 on cluster scott.cluster1; --为簇创建索引
//1.首先创建簇表
SQL> create cluster cluster1(share_col number(10));
Cluster created
SQL> create table tab1(sno number(10),sname varchar2(20)) cluster cluster1(sno);
Table created
SQL> create table tab2(sno number(10),saddr varchar2(20)) cluster cluster1(sno);
Table created
SQL> create index cluster_index on cluster cluster1;
Index created
SQL> select uc.CLUSTER_NAME,uc.TABLESPACE_NAME,uc.CLUSTER_TYPE from user_clusters uc where uc.CLUSTER_NAME='CLUSTER1';
CLUSTER_NAME TABLESPACE_NAME CLUSTER_TYPE
------------------------------ ------------------------------ ------------
CLUSTER1 USERS INDEX
SQL> select ut.TABLE_NAME,ut.TABLESPACE_NAME,ut.CLUSTER_NAME from user_tables ut where ut.TABLE_NAME='TEST1';
TABLE_NAME TABLESPACE_NAME CLUSTER_NAME
------------------------------ ------------------------------ ------------------------------
SQL> select ut.TABLE_NAME,ut.TABLESPACE_NAME,ut.CLUSTER_NAME from user_tables ut where ut.CLUSTER_NAME='CLUSTER1';
TABLE_NAME TABLESPACE_NAME CLUSTER_NAME
------------------------------ ------------------------------ ------------------------------
TAB2 USERS CLUSTER1
TAB1 USERS CLUSTER1
SQL>
先删除表,再删除簇表
|
存放临时数据,可以使用临时表;临时表被每个session
单独使用,即:不同session看到的临时表中的数据可能不一
样。
如果在退出session时删除临时表中的数据,可以使用on
commit preserve rows;如果在用户commit或rollback时删
除临时表中的数据,可以使用on commit delete rows;
从v$sort_usage中查看正在使用临时表空间的session信
息和SQL语句的ID号,从v$sort_segment中查看临时表空间中
的段的使用情况。
临时表在临时表空间中保存。
SQL> create table test_partition(id number(20),account number(20))
2 partition by range(id)(
3 partition part1 values less than(1000),
4 partition part2 values less than(2000),
5 partition part3 values less than(3000));
Table created
SQL> select utp.table_name,utp.partition_name,utp.high_value from user_tab_partitions utp where utp.table_name='TEST_PARTITION';
TABLE_NAME PARTITION_NAME HIGH_VALUE
------------------------------ ------------------------------ --------------------------------------------------------------------------------
TEST_PARTITION PART1 1000//<1000
TEST_PARTITION PART2 2000>=1000 和<2000
TEST_PARTITION PART3 3000
SQL> insert into test_partition part1 values(1,100);
1 row inserted
SQL> insert into test_partition values(1000,200);
1 row inserted
SQL> insert into test_partition
1 row inserted
SQL> insert into test_partition values(5000,400);
insert into test_partition values(5000,400)
ORA-14400: 插入的分区关键字未映射到任何分区
SQL> select * from test_partition partition(part1);
ID ACCOUNT
--------------------- ---------------------
1 100
SQL>
SQL> select * from test_partition partition(part2);
ID ACCOUNT
--------------------- ---------------------
1000 200
SQL> alter table test_partition add partition part4 values less than(
maxvalue);//无上限
Table altered
SQL> insert into test_partition values(6000,600);
1 row inserted
SQL> select * from test_partition partition(part4);
ID ACCOUNT
--------------------- ---------------------
6000 600
SQL>
|
SQL> create table test_partition_hash(id number(20),name varchar(20))
2 partition by
hash(id)(//散列分区是通过hash算法得到分区来进行的
3 partition part1,partition part2,partition part3);
Table created
SQL> select utp.table_name,utp.partition_name,utp.high_value from user_tab_partitions utp where utp.table_name='TEST_PARTITION_HASH';
TABLE_NAME PARTITION_NAME
HIGH_VALUE
------------------------------ ------------------------------ --------------------------------------------------------------------------------
TEST_PARTITION_HASH PART1 //所以不存在high_value
TEST_PARTITION_HASH PART2
TEST_PARTITION_HASH PART3
SQL> insert into test_partition_hash values(1,'张三');
1 row inserted
SQL> insert into test_partition_hash values(2,'李四');
1 row inserted
SQL> insert into test_partition_hash values(3,'王五');
1 row inserted
SQL>
SQL> select * from test_partition_hash partition(part1);
ID NAME
--------------------- --------------------
SQL> select * from test_partition_hash partition(part2);
ID NAME
--------------------- --------------------
1 张三
3 王五
SQL> select * from test_partition_hash partition(part3);
ID NAME
--------------------- --------------------
2 李四
SQL>
|
SQL> create table test_partition_list(id number(20),name varchar2(20),address varchar2(20))
2 partition by list(address)(
3 partition 上北 values('九江'),
4 partition 下南 values('赣州','鹰潭'),
5 partition 左西 values('抚州','新余'),
6 partition 右东 values('景德镇'));
Table created
SQL> insert into test_partition_list values(1,'吴xx','九江');
1 row inserted
SQL> insert into test_partition_list values(2,'陈xx','赣州');
1 row inserted
SQL> insert into test_partition_list values(3,'邹xx','抚州');
1 row inserted
SQL> insert into test_partition_list values(4,'刘xx','景德镇');
1 row inserted
SQL> select * from test_partition_list partition(上北);
ID NAME ADDRESS
--------------------- -------------------- --------------------
1 吴xx 九江
SQL> select * from test_partition_list partition(下南);
ID NAME ADDRESS
--------------------- -------------------- --------------------
2 陈xx 赣州
SQL>
|
SQL> create table test_partition_compass(
2 id number(20),name varchar2(20))
3 partition by range(id)//主分区
4 subpartition by hash(name)//子分区
5 subpartitions 4(//每个主分区包括4个子分区
6 partition part1 values less than(100),//第一个分区
7 partition part2 values less than(200),
8 partition part3 values less than(maxvalue));
Table created
通过EM查看表的分区信息如下:
A browser with Javascript enabled is required for this page to operate properly.
|
引用分区:基于由外键引用的父表的分区的方
法,它依赖已有的父表子表的关系,子表通过外键
关联到父表,进而继承了父表的分区方式而不需自
己创建,子表还继承了父表的维护操作。
1,主表是范围分区,子表是引用分区
2,主表是列表分区,子表是引用分区
3,主表是散列分区,子表是引用分区
//创建范围分区
SQL>
SQL> create table test_partition_student(
2 id number(10),name varchar2(20),grade varchar2(20),constraints pk_student primary key(id))
3 partition by range(id) (
4 partition part1 values less than(100),
5 partition part2 values less than(200),
6 partition part3 values less than(maxvalue));
Table created
SQL> create table test_partition_score(
2 id number(10) primary key ,sid number(10),goal number(10),constraints fk_student_score foreign key(sid)
3 references test_partition_student(id))
4 partition by reference(fk_student_score);
create table test_partition_score(
id number(10) primary key ,sid number(10),goal number(10),constraints fk_student_score foreign key(sid)
references test_partition_student(id))
partition by reference(fk_student_score)
ORA-14652: 不支持引用分区外键,关联的外键必须是非空
SQL>
SQL> create table test_partition_score(
2 id number(10) primary key ,
sid number(10) not null,goal number(10),constraints fk_student_score foreign key(sid)
3 references test_partition_student(id))
4 partition by reference(fk_student_score);
Table created
SQL>
SQL> select upt.table_name,upt.partition_name,upt.high_value from user_tab_partitions upt where upt.table_name in(upper('test_partition_score'),upper('test_partition_student'));
TABLE_NAME PARTITION_NAME HIGH_VALUE
------------------------------ ------------------------------ --------------------------------------------------------------------------------
TEST_PARTITION_STUDENT
PART1100
TEST_PARTITION_STUDENT PART2 200
TEST_PARTITION_STUDENT PART3 MAXVALUE
TEST_PARTITION_SCORE
PART1
TEST_PARTITION_SCORE PART2
TEST_PARTITION_SCORE PART3
6 rows selected
分区名称相同
SQL> insert into TEST_PARTITION_STUDENT values(1,'张三','二年级');
1 row inserted
SQL> insert into TEST_PARTITION_STUDENT values(111,'李四','三年级');
1 row inserted
SQL> insert into TEST_PARTITION_SCORE values(1,1,100);
1 row inserted
SQL> insert into TEST_PARTITION_SCORE values(2,111,99);
1 row inserted
SQL> select * from TEST_PARTITION_STUDENT partition(part1);
ID NAME GRADE
----------- -------------------- --------------------
1 张三 二年级
SQL> select * from TEST_PARTITION_SCORE partition(part1);
ID SID GOAL
----------- ----------- -----------
1 1 100
SQL>
|
围分区,它是范围分区的扩展 。
在数据仓库中有广泛的应用。
SQL> create table test_partition_interval(
2 id number(10),name varchar2(20),num number(20),_date date)
3 partition by range(_date)
4 interval(NUMTOYMINTERVAL(1,'MONTH'))(
5 partition part1 values less than(to_date(20140101,'yyyymmdd')));
create table test_partition_interval(
id number(10),name varchar2(20),num number(20),
_datedate)
partition by range(_date)
interval(NUMTOYMINTERVAL(1,'MONTH'))(
partition part1 values less than(to_date(20140101,'yyyymmdd')))
ORA-00911: 无效字符//不能使用_开头的属性名称
SQL>
SQL> create table test_partition_interval(
2 id number(10),name varchar2(20),num number(20),
s_datedate)
3 partition by range(s_date)
4 interval(NUMTOYMINTERVAL(1,'MONTH'))(//按照一个月来间隔增长的
5 partition part1 values less than(to_date(20140101,'yyyymmdd')));//初始的月份
Table created
SQL> select sysdate from dual;
SYSDATE
-----------
13-1月-15 1:
SQL> INSERT INTO test_partition_interval VALUES(1,'上衣',20,'01-1月-2014');
1 row inserted
SQL>
SQL> INSERT INTO test_partition_interval VALUES(1,'上衣',20,'01-2月-2014');
1 row inserted
SQL> select utp.table_name,utp.partition_name,utp.high_value from user_tab_partitions utp where utp.table_name='TEST_PARTITION_INTERVAL';
TABLE_NAME PARTITION_NAME HIGH_VALUE
------------------------------ ------------------------------ --------------------------------------------------------------------------------
TEST_PARTITION_INTERVAL PART1 TO_DATE(' 2014-01-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIA
TEST_PARTITION_INTERVAL SYS_P41 TO_DATE(' 2014-02-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIA
TEST_PARTITION_INTERVAL SYS_P42 TO_DATE(' 2014-03-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIA
SQL> INSERT INTO test_partition_interval VALUES(1,'上衣',20,'01-10月-2014');
1 row inserted
SQL> select utp.table_name,utp.partition_name,utp.high_value from user_tab_partitions utp where utp.table_name='TEST_PARTITION_INTERVAL';
TABLE_NAME PARTITION_NAME HIGH_VALUE
------------------------------ ------------------------------ --------------------------------------------------------------------------------
TEST_PARTITION_INTERVAL PART1 TO_DATE(' 2014-01-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIA
TEST_PARTITION_INTERVAL SYS_P41 TO_DATE(' 2014-02-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIA
TEST_PARTITION_INTERVAL SYS_P42 TO_DATE(' 2014-03-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIA
TEST_PARTITION_INTERVAL SYS_P43 TO_DATE(' 2014-11-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIA
SQL>
|
上,即建立在函数或表达式的计算结果上,来完成
SQL>
SQL> create table test_partition_virtual(
2 id number(10),name varchar2(20),num number(20),price number(8,2),total_price as
price*numvirtual)
3 partition by range(total_price)(
4 partition part1 values less than(1000),
5 partition part2 values less than(2000),
6 partition part3 values less than(maxvalue));
ORA-02000: 缺失 ( 关键字
SQL>
SQL>
SQL> create table test_partition_virtual(
2 id number(10),name varchar2(20),num number(20),price number(8,2),total_price as
(price*num)virtual)
3 partition by range(total_price)(
4 partition part1 values less than(1000),
5 partition part2 values less than(2000),
6 partition part3 values less than(maxvalue));
Table created
SQL> insert into test_partition_virtual(id,name,num,price) values(1,'上衣',10,100);
1 row inserted
SQL> insert into test_partition_virtual(id,name,num,price) values(1,'上衣',20,100);
1 row inserted
SQL> select * from test_partition_virtual partition(part1);
ID NAME NUM PRICE TOTAL_PRICE
----------- -------------------- --------------------- ---------- -----------
SQL> select * from test_partition_virtual partition(part2);
ID NAME NUM PRICE TOTAL_PRICE
----------- -------------------- --------------------- ---------- -----------
1 上衣 10 100.00 1000
SQL>
|
区的控制和管理,它没有了范围分区或列表分区的
界限。
SQL> alter table test_partition add partition values less than(6000);
alter table test_partition add partition values less than(6000)
ORA-14074: 分区界限必须调整为高于最后一个分区界限
分区因为是添加在最后以后分区上的
//删除分区
SQL> alter table test_partition drop partition part4;
Table altered
//增加分区
SQL> alter table test_partition add partition part4 values less than(7000);
Table altered
//拆分分区
SQL> alter table test_partition merge partitions part1,part2 into partition part2;
Table altered
//合并分区
SQL> alter table test_partition split partition part2 at(1000) into (partition part1 ,partition part2);
SQL> alter table test_partition split partition part2 at(1000) into (partition part1 ,partition part2);
Table altered
//截断分区
SQL> alter table test_partition truncate partition part3;
Table truncated
SQL>
|