row-archival(ROW ARCHIVE) management 12C新特性
在一些场景中,当我们不需要表中的某些行时,需要发布delete语句来删除。
但是有时候并不是想在物理上真正的删除这些数据,在传统的表设计中,我们一般都加多一个栏位来表示逻辑删除。
比如is_delete,当应用程序在处理时,把is_delete也加入到where条件中来表示行是不是真正的删除了.
在12C中,引入了一个新特性叫作row archive,可以让数据库自动来做这些操作.这个特性也叫作In-Database Archiving.
测试row-archival
create table t1 (a int,b varchar2(10));
insert into t1 select rownum a,'Test' b from dual connect by rownum<=10;
commit;
select * from t1;
-- 允许表的ROW ARCHIVE
alter table t1 row archival;
select column_name,DATA_TYPE,NULLABLE from user_tab_cols where table_name='T1' order by COLUMN_ID;
COLUMN_NAME DATA_TYPE N
----------------- --------------- -
A NUMBER Y
B VARCHAR2 Y
SYS_NC00003$ RAW Y
ORA_ARCHIVE_STATE VARCHAR2 Y
-- 在允许row archival后,系统会自动会表增加栏位ORA_ARCHIVE_STATE,用来表示数据可用性情况。
-- 如果我们用select * from t1这种方式,这个栏位是不会被显示的,只有显式指定栏位,才会在结果集中显示栏位.
select * from t1;
select a,b,ora_archive_state from t1;
select a,b,"SYS_NC00003$" from t1;
-- 通过显式指定,可以查出ora_archive_state,默认值为0,表示该行对应用程序可见.
-- 修改ORA_ARCHIVE_STATE的值为非0对应用程序不可见.
update t1 set ora_archive_state=1 where a=1;
update t1 set ora_archive_state=2 where a=2;
update t1 set ora_archive_state='-1' where a=3;
update t1 set ora_archive_state='A' where a=4;
update t1 set ora_archive_state='a' where a=5;
update t1 set ora_archive_state='-0' where a=6;
commit;
select * from t1;
select a,b,ora_archive_state from t1;
A B O
---------- ---------- -
7 Test 0
8 Test 0
9 Test 0
10 Test 0
可以看到现在在应用程序是查不出a=1的这条记录了.
但是对于管理员或是某些特殊的会话,我又计划想他们看见这些行。可以通过设置会话来改变.
alter session set row archival visibility=ALL;
select a,b,ora_archive_state from t1;
alter system set row archival visibility=ALL;
当前会话又可以看到之前被隐藏的行了.
-- 取消row archive
alter table t1 no row archival;
select a,b from t1;
select column_name,DATA_TYPE,NULLABLE from user_tab_cols where table_name='T1' order by COLUMN_ID;
参考:http://abner.blog.chinaunix.net/uid-20785090-id-4445403.html
「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。




