赞
踩
CREATE INDEX 索引名 ON 表名(列名);
CREATE INDEX 索引名 ON 表名(列名1, 列名2, 列名3, ...);
create unique index 唯一索引名 on 表名(字段1,字段2..);
drop index 索引名;
—根据索引名,查询表索引字段
select * from user_ind_columns where index_name='索引名';
—根据表名,查询一张表的索引
select * from user_indexes where table_name='表名';
语法:
create [or replace] trigger trigger_name --触发器名称
instead of trigger_event --触发事件
on view_name --视图名称
for each row --替代触发器必须指定为行级的触发器
[when trigger_condition] --触发条件
trigger_body --触发体,PL/SQL块
exp:
创建触发器:实现id的隐式自增
create or replace trigger tri_match_diff
before insert on T_MATCH_DIFF_RESULT
for each row
declare
next_id number;
begin
select seq_match_diff_result_id.nextval into next_id from dual;
:new.id :=next_id;
end;
和mysql中使用auto_increment不同,oracle中使用序列来实现主键自增,使用序列前必须要先创建一个序列:
create sequence seq_sale_id序列名称
increment by 1 每次增长多少
start with 1 从几开始
minvalue 1 最小值
maxvalue 999999999 最大值
cycle/no cycle 序列到达最大值之后怎么办,一般去cycle
cache 20 需要不需要使用缓存,就是一次生成多少个序列的值,如果生成了多个序列值,如果缓存中有数据, 就不需要查询缓存了
order/noorder 获取序列的时候是否按顺序给值。如果多用户一起获取序列的值,使用order可以保证序列值的顺序按访问序列的事件排序
exp:
create sequence seq_name
increment by 1
start with 1
minvalue 1
maxvalue 9999999
cache 20
cycle;
使用序列获取序列的下一个值:
select seq_name.nextval from dual
获取序列的当前值:
select seq_name.currval from dual
插入数据时
insert into table(id,name) values(seq_name.nextval,'test')
删除序列
dorp sequence [用户名.]seq_name
修改序列
alert sequence seq_name increment by 10 nomaxvalue nocycle cache 10
修改序列只能修改这几个值,不能修改初始值
查看序列
查看当前用户下的所有序列:
select * from user_sequences
查看所有用户下的所有序列:
select * from all_sequences
select * from dba_sequences
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。