天天看點

oracle的序列與同義詞

一.序列

1.格式:

create sequence 序列名

start with n

increment by n

maxvalue n|nomaxvalue 

minvalue n|nominvalue

cache n|nocache (把n個連續的序列号儲存在記憶體中)

cycle n|nocycle|cycle 20 (是否循環)

2.建立一個序列

create sequence t_se

start with 2000

increment by 10

maxvalue 100000

nocache

nocycle

3.删除一個序列

 drop sequence t_se;

4.查詢一個序列屬性

(1)select sequence_name,min_value,max_value,increment_by,

cycle_flag,cache_size,last_number

from user_sequences

(2)

select object_name,object_type,created,status

from user_objects

where object_type!='TABLE'

and object_type!='INDEX'

5.查詢序列值

select t_se.nextval from dual;(查詢下一個值)

select t_se.currval from dual;(查詢目前值)

6.向表中插入序列值

insert into test(id) values(t_se.nextval);

7.修改序列

alter sequence t_se

increment by 11

maxvalue 999999

cache 50

二.同義詞

1.建立同義詞

create   synonym zgk.t for zgk.test;

create public synonym t for zgk.test;(共有的,所有使用者都可以查詢)

2.删除同義詞

drop synonym t;

drop public synonym t;

3.查詢同義詞

select * from zgk.t;

4.查詢序列屬性資訊

select object_name,object_type from

user_objects

where object_type like 'SYN%'

5.查詢序列資訊

select synonym_name,table_owner,table_name

from user_synonyms

繼續閱讀