identity是sybase中的一个概念,如果你想使这个字段唯一,你可以使用主键及sequence(序列)。
解决方案 »
- oracle数据库远程访问,查询某些表无响应
- 怎么用青蛙 导出insert的语句?
- Oracle9i数据库系统优化与调整,决对是一本好书
- 视图转换成存储过程求救
- Oracle客户端连接问题
- oracle和SQL SERVER有哪些区别
- 请教各位一个sql语句的问题,急!!!! 多谢!
- 一个问题 ,全部的分相送!!!
- penitent(只取一瓢)和弱水三千请快来,我建好了一个包,请问一下在SQL/PLUS怎么才能得到它返回的记录集?
- 匯出XML方式 請教
- Oracle 8i安装完成后,在DOS窗口输入svrmgrl命令,却得到ORA-12560: TNS :协议适配器错误
- a trigger problem,need ur assistant
你得用序列
create sequence sqname start with 1 increment by 1 maxvalue 100 nocycle
insert into table values(sqname.nextval);Keyword Description
START WITH Defines the first number that the sequence will
generate. The default is one.INCREMENT BY Defines the increase or decrease for subsequently
generated numbers. To specify a decreasing
sequence, use a negative INCREMENT BY.MINVALUE The lowest number the sequence will generate.
This is the bounding value in a decreasing
sequence. The default MINVALUE is the keyword
NOMINVALUE, which translates to 1 for an
increasing sequence and to –1026 for a decreasing
sequence.MAXVALUE The largest number that the sequence will
generate. This is the bounding value in the
default, increasing sequence. The default
MAXVALUE is the keyword NOMAXVALUE which
translates to 1027 for an increasing sequence and
to –1 for a decreasing sequence.CYCLE Configures the sequence to repeat numbers after
reaching the bounding value.NOCYCLE Configures the sequence to not repeat numbers
after reaching the bounding value. This is the
default. When you try to generate the
MAXVALUE+1, an exception will be raised.CACHE Defines the size of the block of sequence
numbers held in memory. The default is 20.NOCACHE Forces the data dictionary to be updated for each
sequence number generated, guaranteeing no
gaps in the generated numbers.
第一步:创建SEQUENCE
create sequence s_country_id increment by 1 start with 1 maxvalue 999999999;
第二步:创建一个基于该表的before insert 触发器,在触发器中使用该SEQUENCE
create or replace trigger bef_ins_t_country_define
before insert on t_country_define
referencing old as old new as new for each row
begin
select s_country_id.nextval into :new.country_id from dual;
end;