oracle:索引、视图和闪回数据归档

本文介绍数据库索引的创建、查询及修改方法,并详细解释了B-树索引和位图索引的区别。此外,还介绍了如何创建、查询、修改及删除视图,并涉及闪回归档的创建和管理。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

索引

准则:当任何单个查询要检索的行少于或等于整个表行数的10%时,就应当创建索引。
B-树索引:索引的候选列应该是用来存储很大范围的值的列
位图索引:包含小范围值的列

1.创建B-树索引

注意:由于性能原因,应该将索引与表存储到不同的表空间中。

假设test表包含很多行

select id,type
from test
where type='01';
create index i_test_type on test(type);

唯一索引

create unique index i_test_id on test(id);

复合索引

create index i_test_id_type on test(id, type);
2.创建基于函数的索引
select id,type
from test
where type=UPPER('SFZ');
create index i_func_test_type on test(UPPER(type));

注意:使用基于函数的索引,必须要将初始化参数query_rewrite_enabled设置为true。

3.获取有关信息的索引
select index_name, table_name, uniqueness, status
from user_indexes
where table_name='test';
4.获取列索引的信息
select index_name, table_name, column_name
from user_ind_columns
where table_name='test';
5.修改索引
alter index i_test_id_type rename to i_test_id_and_type;
6.删除索引
drop index i_test_id_and_type;
7.创建位图索引
create bitmap index i_order on order(status);

视图

注意:视图并不存储行,他们始终存储在表中。视图返回存储在表中的行

1.创建视图
connect system/systemgrant create view to zoey;
connect zoey/zoey

create view test_view asselect * from test where type='02';

使用视图

select id from test_view;

注意:简单视图支持DML操作,复杂视图不支持DML操作。

2.创建具有check option约束的视图指定对视图执行的DML操作必须满足子查询的条件。
create view test_view2 asselect * from test where type='02'
with check option constraint test_view2;
3.创建具有read only约束的视图(只读)
create view test_view3 asselect * from test where type='02'
with read only constraint test_view2;
4.获取有关视图定义的信息
describe test_view3;
5.获取有关视图的约束信息
select constraint_name, constraint_type, status , deferrable, deferred
from user_constraintswhere table_name='test';
6.修改视图
create or replace view test_view3 asselect * from test where type in ('02', '01');
7.删除视图
drop view test_view3;

五.闪回数据归档

create flashback archive test_archivetablespace example --归档在example创建
quota 1 M --限额是1M
retention 1 DAy;--保留期限是1天

停止归档

alter zoey.test no flashback archive;

清除归档中的所有数据

alter flashback archive test_archive purge all;

删除闪回归档

drop flashback archive test_archive;
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值