日期:2014-05-17  浏览次数:21073 次

oracle:在触发器中,如何获得自增id的值,并实现更新数据!
在项目中,有一张表,需要在用户在插入一条记录时,同时更新字段other_id,要求other_id的值为刚插入的记录的id(id为自增字段),请问怎么写sql啊?
我的思路如下:
表:
create table a (id int not null,nvarchar(20),other_id int);
触发器:
create trigger  changeField_trigger after insert
    on a
    for each row
    begin 
      update a set other_id=:new.id where id=:new.id;
    end;
但是插入数据时会报错!请问高手怎么解决啊?急。。。。。。。等着用啦!!
------最佳解决方案--------------------
楼主百度一下触发器和SEQUENCE
------其他解决方案--------------------
你虽然没有说明问题重点,但还是谢谢,分给你吧!