使用SQL触发器时,我遇到了一个奇怪的问题。
Java代码:
触发:
发生了什么:
请帮助我,因为我无法在互联网上找到任何解决方案。
更新(触发代码): -
CREATE OR REPLACE TRIGGER ISF.MATRIX_TEAM_STRATEGY_AUD_AR_TR
AFTER DELETE OR INSERT OR UPDATE
ON ISF.MATRIX_TEAM_STRATEGY
REFERENCING OLD AS OLD NEW AS NEW
FOR EACH ROW
DECLARE
v_upd_login varchar2(30);
insert_error EXCEPTION;
PRAGMA EXCEPTION_INIT(insert_error, -20501);
v_action_cd CHAR(1);
begin
IF INSERTING THEN
v_action_cd := 'I';
ELSIF UPDATING THEN
v_action_cd := 'U';
ELSE
v_action_cd := 'D';
END IF;
-- get the user id;
select user into v_upd_login from dual;
-- add an audit record
if inserting or updating then
insert into isf.matrix_team_strategy_aud
(
TEAM_STRATEGY_ID,
TEAM_ID,
STRATEGY_ID,
PORTFOLIO_LIST_ID,
SUB_TEAM_ID,
INS_TS,
UPD_TS,
INS_LOGIN,
UPD_LOGIN,
APP_USER,
ACTION_CD
)
values
(
:new.TEAM_STRATEGY_ID,
:new.TEAM_ID,
:new.STRATEGY_ID,
:new.PORTFOLIO_LIST_ID,
:new.SUB_TEAM_ID,
:new.INS_TS,
:new.UPD_TS ,
:new.INS_LOGIN,
v_upd_login,
:new.APP_USER,
v_action_cd
);
elsif deleting then
insert into isf.matrix_team_strategy_aud
(
TEAM_STRATEGY_ID,
TEAM_ID,
STRATEGY_ID,
PORTFOLIO_LIST_ID,
SUB_TEAM_ID,
INS_TS,
UPD_TS,
INS_LOGIN,
UPD_LOGIN,
APP_USER,
ACTION_CD
)
values
(
:old.TEAM_STRATEGY_ID,
:old.TEAM_ID,
:old.STRATEGY_ID,
:old.PORTFOLIO_LIST_ID,
:old.SUB_TEAM_ID,
:old.INS_TS,
sysdate,
:old.INS_LOGIN,
v_upd_login,
:old.APP_USER,
v_action_cd
);
end if;
exception
when dup_val_on_index then
null;
when others then
raise_application_error(-20501,'Insert error ' || sqlerrm);
-- dbms_output.put_line ('Error in audit trigger of isf.matrix_team_strategy_aud Sql code ' ||sqlcode || ' ' ||sqlerrm);
end;