Oracle中的PL/SQL编程(一)

在PL/SQL中 建立索引是为了加快查询速度,但如果索引过多或设置不合理可能会降低查询速度
一般来说只对在数据量比较大的表中,对于需要经常查询较少修改的列建立索引
--创建单一索引 (在emp表上的sal列创建名为sal_index的索引)
create index sal_index on emp(sal);
--创建复合索引(在emp表上的sal,ename列创建名为com_index 的复合索引)
create index com_index on emp(sal,ename);
--创建唯一索引(在emp表上的ename列创建名为ename_unqiue_index 的唯一索引
--如果要建立唯一索引的列已经有重复项则不能建立唯一索引
create unique index  ename_unqiue_index on emp(ename);
--删除索引
 drop index 索引名;
--显示当前用户的所有索引
select * from user_indexes;


--序列
--创建序列
create sequence seq_num1   --序列名为seq_num1
    start with 1           --其实元素为1 
    increment by 1         --  步长为1 
    maxvalue 20            --生成的最大值为20 
    minvalue 1            --生成的最大值为20 
    nocycle                 --达到最大值后不循环 
    cache 2              --缓存为2


--使用序列  
--假如有张myuser表  列为 userid username userpwd 那么我要使用序列插入一行命令如下
insert(seq_num1.nextval,'zzc','zzc');
--查询当前用户的所有序列
select * from user_sequences;

--创建视图
create or replace view v_emp as select empno,ename,job from emp;




猜你喜欢

转载自124654439.iteye.com/blog/2145174
今日推荐