Informix中的serial在oracle中如何转换?

来源:互联网 发布:js循环语句 编辑:程序博客网 时间:2024/05/16 10:54


Informix的serial变量类型是一种自增数据类型。在create table时将字段定义为serial类型,就可以实现变量值的自动增长,使用起来非常方便。

Oracle中实现serial

只需要创建一个sequence变量和一个基于目标数据库的trigger(触发器)

 

将表t_user的字段ID设置为自增:(用序列sequence的方法来实现)

----创建表 
create tablestudent(

 stu_no number,

 stu_namevarchar2(40),

stu_age number

),

----创建序列 
create sequence user_seq 
increment by 1  
start with 1 
nomaxvalue 
nominvalue 
nocache

----创建触发器 
create or  replace trigger tr_user 
before insert on t_user 
for each row 
begin 
select user_seq.nextval into :new.id from dual; 
end; 

阅读全文
0 0
原创粉丝点击