日期:2014-05-16  浏览次数:20393 次

关于oracle 索引

创建唯一索引,ind_name为索引名称,TBS为存放索引段的表空间.(索引表空间)
create unique index ind_name on table_name(col_name) tablespace tbs;


重建索引,如果一个索引创建了很长时间就会产生碎片从而影响查询性能,这时需要重建索引.rebuild意思为重建
alter index ind_name rebuild;


有时候由于空间的调整,把索引从一个表空间移到另外一个表空间
1.先查看当前所在的表空间

select index_name,tablespace_name from dba_indexes where index_name='INDEX_PS';
2.移到另外一个product表空间

alter index index_ps rebuild tablespace product;
3.再次查看表空间,确定索引是否成功移到另一个表空间
select index_name,tablespace_name from dba_indexes where index_name='INDEX_PS';


查看创建索引都语句

set long 10000;
select dbms_metadata.get_ddl('INDEX','IND_NAME','ZWC');

?

1.创建表,通过utlxplan.sql脚本
SQL> @?/rdbms/admin/utlxplan.sql
2. 创建同义词为了多个用户可以共享一个plan_table 并授权给public
SQL> create public synonym plan_table for plan_table;
SQL> grant all on plan_table to public;
3.创建plustrace 角色
SQL> @?/sqlplus/admin/plustrce.sql 执行这个脚本就可以了。
4、将角色权限授予public
sql>grant plustrace to public;
完成以上几步就可以使用autotrace 功能
set timing on --显示执行时间
set autotrace on 查看执行计划和查询信息
set autotrace traceonly 只显示执行计划,但不显示查询输出

?

?