hibernate触发器碰到的坑

**

insert触发器更新字段值

oracle
create or replace trigger cs
before insert
on tablename
fro each row //oralce是对每一行影响有;new,:old
when (new.cloumn>0)//这里的new没:
begin
select cloumn_0 :new.cloumn_0 from table2 where table2.pphid=table.pphid; //一定要做末尾加;
end
**
sql server
CREATE TRIGGER cs
ON table
after INSERT
AS
DECLARE @phidcnt BIGINT;
DECLARE @phid BIGINT;
DECLARE @bz VARCHAR(4000);

BEGIN
set nocount on//如果是通过hibernate触发的一定要加否则会报影响条数不一致的错误( Batch update returned unexpected row count from update; actual row count: 2; expected: 1);
select @phidcnt=phid_cntchg from inserted
select @phid=phid from inserted
IF(@phidcnt>0)
select @bz=remarks from PCM3_CNT_change_D where phid=@phidcnt;
UPDATE table SET remarks=@bz WHERE table.PHID=@phid

END;

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章