create OR REPLACE trigger naoms_fims_notuserinfo_trigger
before update on naoms_fims_notuserinfo for each row
declare
rownums number(5);
begin
rownums = select count(*) from naoms_fims_notuserinfo n where n.update_date = to_date(to_char(sysdate,'yyyy-mm-dd'),'yyyy-mm-dd') and n.deptname = new.deptname and n.resouretype = new.resouretype;
if rownums>0 then
update naoms_fims_notuserinfo n set n.update_date = sysdate,n.notuse_source_count = new.notuse_source_count,n.description = new.description where n.deptname = new.deptname and n.resouretype = new.resouretype;
else
insert into naoms_fims_notuserinfo(id,notuse_source_count,description,update_date,update_employee,version,RESOURETYPE,DEPTNAME)
values(config_seq.nextval,new.notuse_source_count,new.description,sysdate,new.update_employee,0,new.RESOURETYPE,new.DEPTNAME);
end if;
end naoms_fims_notuserinfo_trigger;
uj5u.com熱心網友回復:
想要更新的時候 出發是不是已經存在資料,沒有就執行插入uj5u.com熱心網友回復:
select count(*) into rownums from ...給rownums 賦值這樣賦
uj5u.com熱心網友回復:
如樓上在ORACLE中通過SELECT賦值的是通過INTO處理的另外,感覺你要實作的功能,不需要用觸發器實作,
通過MERGE就可以實作
LZ可以看看MERGE語法看看符合不符合你的需要
uj5u.com熱心網友回復:
使用merge into 的時候 沒有資料源表,我用的是更新陳述句,這個怎么用啊uj5u.com熱心網友回復:
能不能寫個例句,資料不是來自表,而是來自即將更新的資料uj5u.com熱心網友回復:
想要更新的時候 出發是不是已經存在資料,沒有就執行插入沒有被更新資料,是不執行這個觸發器的;
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/113591.html
標籤:開發
