1 创建序列,新建了一个列作为主键
create sequence pbaseinfo
INCREMENT BY 1
START WITH 1
NOMAXVALUE
NOCYCLE
NOCACHE;
为主键赋值
UPDATE C_PBASEINFO C SET C.NEWID = pbaseinfo.nextval
定义好sequence后,你就可以用currVal,nextVal取得值。
CurrVal:返回 sequence的当前值
NextVal:增加sequence的值,然后返回 增加后sequence值
得到值语句如下:
SELECT Sequence名称.CurrVal FROM DUAL;
如得到上边创建Sequence值的语句为:
select seqtest.currval from dual
序列的删除修改
drop sequence pbaseinfo
alter sequence SEQTEST maxvalue 9999999;
select wmx.nextval from dual
在代码中添加相关注解
@Column(name="NEWID")
@SequenceGenerator(name="PBASEINFO",sequenceName="pbaseinfo",allocationSize = 1)
@GeneratedValue(generator="PBASEINFO",strategy=GenerationType.SEQUENCE)
hibernate 自增字段注解的写法