ITPub博客

首页 > Linux操作系统 > Linux操作系统 > 【实验】【聚簇】聚簇中的表不允许truncate

【实验】【聚簇】聚簇中的表不允许truncate

原创 Linux操作系统 作者:secooler 时间:2009-08-14 17:20:26 0 删除 编辑
1.创建聚簇过程
sec@ora10g> create cluster cluster_test(id int);
sec@ora10g> create table tab_cluster1(id int primary key, name1 varchar2(30)) cluster cluster_test(id);
sec@ora10g> create table tab_cluster2(id int primary key, name2 varchar2(30)) cluster cluster_test(id);
sec@ora10g> create index idx_cluster_test on cluster cluster_test;
参见《【实验】【聚簇】聚簇(Cluster)和聚簇表(Cluster Table)的创建与总结》
http://space.itpub.net/519536/viewspace-610869

2.初始化几行聚簇表的数据
sec@ora10g> insert into TAB_CLUSTER1 values (1,'Andy');
sec@ora10g> insert into TAB_CLUSTER1 values (2,'Secooler');
sec@ora10g> insert into TAB_CLUSTER1 values (3,'Hou');
sec@ora10g> insert into TAB_CLUSTER2 values (1,'Anna');
sec@ora10g> insert into TAB_CLUSTER2 values (2,'W');
sec@ora10g> insert into TAB_CLUSTER2 values (3,'Xu');
sec@ora10g> commit;

3.查看聚簇表所属的聚簇及聚簇表信息
sec@ora10g> select owner,table_name,cluster_name from dba_tables where wner='SEC' and table_name in ('TAB_CLUSTER1','TAB_CLUSTER2');

OWNER    TABLE_NAME      CLUSTER_NAME
-------- --------------- ------------------
SEC      TAB_CLUSTER2    CLUSTER_TEST
SEC      TAB_CLUSTER1    CLUSTER_TEST

sec@ora10g> select * from TAB_CLUSTER1;

        ID NAME1
---------- ------------------------------
         2 Secooler
         3 Hou
         1 Andy

sec@ora10g> select * from TAB_CLUSTER2;

        ID NAME2
---------- ------------------------------
         2 W
         3 Xu
         1 Anna

4.模拟truncate表TAB_CLUSTER1,可以看到报错了,聚簇中的表不允许truncate,原因很简单,聚簇在一个块上存储了多个表,必须删除聚簇表中的行来实现删除
sec@ora10g> truncate table TAB_CLUSTER1;
truncate table TAB_CLUSTER1
               *
ERROR at line 1:
ORA-03292: Table to be truncated is part of a cluster


sec@ora10g> truncate table TAB_CLUSTER2;
truncate table TAB_CLUSTER2
               *
ERROR at line 1:
ORA-03292: Table to be truncated is part of a cluster

5.清除聚簇表第一种方法:delete方式删除

6.清除聚簇表第二种方法:通过truncate cluster的方式清除cluster中表数据
sec@ora10g> truncate cluster CLUSTER_TEST;

Cluster truncated.

sec@ora10g> truncate cluster CLUSTER_TEST;

Cluster truncated.

sec@ora10g> select * from TAB_CLUSTER1;

no rows selected

sec@ora10g> select * from TAB_CLUSTER2;

no rows selected

OK,删除成功!

-- The End --

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/519536/viewspace-612370/,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论
Oracle ACE 总监,阿里云MVP,北京大学理学硕士,恩墨学院创始人,教育专家,中国区 Cloudera 首位官方授权大数据讲师,金牌培训专家,BDA大数据联盟创始人,OCM联盟创始人,ACCUG创始人、ACOUG核心专家,Blogger。

注册时间:2008-03-16

  • 博文量
    797
  • 访问量
    7975356