ITPub博客

首页 > 数据库 > Oracle > 【实验】【聚簇】聚簇中的表不允许truncate

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

原创 Oracle 作者:OCMU联盟 时间: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博客 ” ,链接:https://blog.itpub.net/70034820/viewspace-2994300/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论
OCM联盟( Oracle Certified Master Union)是由侯圣文(ACE总监)发起的一个公益组织,旨在为每一个OCM大师提供一个可以继续展示自己才华,技术和实力的平台。

注册时间:2007-05-27

  • 博文量
    799
  • 访问量
    8406983