I do not speak English well. Sorry.
If I define this trigger
create or replace TRIGGER abcdef
after UPDATE of ORGNZT_ID ON COMTNEMPLYRINFO_1
REFERENCING NEW AS NEW OLD AS OLD FOR EACH ROW
BEGIN
update COMTNEMPLYRINFO_1 set ETC_1 = :old.OFFM_TELNO , ETC_2 = '10' where UNIQ_ID = :old.UNIQ_ID;
END;
it compiles. But,
update COMTNEMPLYRINFO_1 set ORGNZT_ID ='ABC' where UNIQ_ID = 'UNIQ_001'
ORA-06512:
ORA-04088: 트리거 'EGOV.ABCDEF'의 수행시 오류
And the trigger I want is:
create or replace TRIGGER abcdef
after UPDATE of ORGNZT_ID ON COMTNEMPLYRINFO_1
REFERENCING NEW AS NEW OLD AS OLD FOR EACH ROW
BEGIN
IF (:NEW.ORGNZT_ID <> :OLD.ORGNZT_ID) THEN
:NEW.ETC_1 := :OLD.OFFM_TELNO;
:NEW.ETC_2 := '10';
END IF;
END;
But I am getting an error:
ORA-04084: 이 트리거 유형에 트리거 NEW 값을 변경할 수 없습니다
04084. 00000 - "cannot change NEW values for this trigger type"
*Cause: New trigger variables can only be changed in before row
insert or update triggers.
*Action: Change the trigger type or remove the variable reference.
How to solve this?
:NEW and :OLD values are available only in BEFORE UPDATE, so your trigger must be like this:
create or replace TRIGGER abcdef
BEFORE UPDATE of ORGNZT_ID ON COMTNEMPLYRINFO_1
FOR EACH ROW
BEGIN
IF (:NEW.ORGNZT_ID <> :OLD.ORGNZT_ID) THEN
:NEW.ETC_1 := :OLD.OFFM_TELNO;
:NEW.ETC_2 := '10';
END IF;
END;
REFERENCING NEW AS NEW OLD AS OLD is redundant, you can skip it if you like.
Related
I have following trigger:
create or replace TRIGGER MY_TIGGER_NAME AFTER UPDATE ON MY_TABLE
REFERENCING OLD AS OLD NEW AS NEW FOR EACH ROW
WHEN ( NEW.STATUS = ANY (10,40,42,44,46,50,60) and OLD.STATUS != NEW.STATUS)
DECLARE
PRAGMA AUTONOMOUS_TRANSACTION;
BEGIN
IF :NEW.ALERT is NULL
THEN
dbms_alert.signal('print_update_event','update_message');
ELSE
dbms_alert.signal( :NEW.ALERT,'update_message');
END IF;
commit;
END;
I would like to change it because it send alert for each row. I would like to send only one alert if more than one row with ALERT column equal NULL was updated and I would like to send one alert for each row with ALERT column NOT equal NULL.
As I understand Oracle variables I can declare local variable in my trigger but this variable will be declared separately for each row so following change has no sense:
create or replace TRIGGER MY_TIGGER_NAME AFTER UPDATE ON MY_TABLE
REFERENCING OLD AS OLD NEW AS NEW FOR EACH ROW
WHEN ( NEW.STATUS = ANY (10,40,42,44,46,50,60) and OLD.STATUS != NEW.STATUS)
DECLARE
PRAGMA AUTONOMOUS_TRANSACTION;
flag NUMBER(1,0) :=0;
BEGIN
IF :NEW.ALERT is NULL and flag=0
THEN
dbms_alert.signal('print_update_event','update_message');
flag:=1;
ELSE
dbms_alert.signal( :NEW.ALERT,'update_message');
END IF;
commit;
END;
Package variable could be used instead local variable but I think that package variable is bad idea because two triggers can be executed in parallel. Maybe I am wrong.
I attach diagram of trigger which shows what I would like to achieve.
How to do it?
I have created a Trigger to insert values in table. But while compiling it, I am getting error as
Error(10,80): PL/SQL: ORA-01745: invalid host/bind variable name
Below is my trigger
CREATE OR REPLACE TRIGGER TR_UPDATE_FR_LOGTYPE1
AFTER INSERT OR UPDATE ON LOGSAPDEALSLIPFUNDREQINTGRTN
FOR EACH ROW
BEGIN
IF (:NEW.RESPONSESTRING LIKE '%Record already exists%'
AND:NEW.LOGTYPE = 'ServiceFault')
THEN
--:NEW.LOGTYPE := 'Success';
Insert into LOGSAPDEALSLIPFUNDREQINTGRTN (LOGTYPE) values (:NEW.LOGTYPE := 'Success');
END IF;
END;
You simply need to edit this way:
...
Insert into LOGSAPDEALSLIPFUNDREQINTGRTN (LOGTYPE) values ('Success');
...
I'm getting the error
Error(2,67): PLS-00049: bad bind variable OLD.DEPTNAME while executing below trigger also getting 'enter binds' prompt in SQL developer
create or replace trigger emp_Dept_view_trig
instead of update on emp_Dept_view
for each row
begin
update department set LOCATION = :NEW.LOCATION where DEPTNAME:OLD.DEPTNAME;
commit;
end;
try this
CREATE OR REPLACE TRIGGER emp_Dept_view_trig
INSTEAD OF UPDATE
ON emp_Dept_view
FOR EACH ROW
BEGIN
UPDATE department
SET LOCATION = :NEW.LOCATION
WHERE DEPTNAME=:OLD.DEPTNAME;
commit; end;
I'm trying to create a trigger that will fire if the Prog_Type = 'EPISODE'. I am receiving a bad binding error - PLS - 000049. I believe there is something wrong with my DECLARE state
CREATE OR REPLACE TRIGGER Seas_Pk_Trigger
BEFORE INSERT OR UPDATE OF Seas_ID ON Season_Table
FOR EACH ROW
DECLARE
Prog_Type VARCHAR2(7);
BEGIN
IF (:OLD.Prog_Type <> 'EPISODE')
THEN SELECT Seas_ID_Seq.nextval into :new.Seas_ID from dual;
END IF;
END Seas_Pk_Trigger;
/
If you are referencing a column in your table, you do not need to declare the column Prog_Type to reference it with a :OLD or :NEW pseudo-record. If Prog_Type is in your table (which I assume it is), then just omit the declaration:
CREATE OR REPLACE TRIGGER Seas_Pk_Trigger
BEFORE INSERT OR UPDATE OF Seas_ID ON Season_Table
FOR EACH ROW
BEGIN
IF (:OLD.Prog_Type <> 'EPISODE')
THEN SELECT Seas_ID_Seq.nextval into :new.Seas_ID from dual;
END IF;
END Seas_Pk_Trigger;
/
I'm not sure how to interpret your statement that you only want this to fire when Prog_Type = 'EPISODE' as your trigger has a <> to EPISODE clause?
I want to keep track of changes to one table in another table. What I need is an after update trigger which writes the name of changed column (if multiple columns are changed then there will be multiple inserts to the CHANGES table),the column's old and new values. How do I do that. I tried this but got an error after updating the table.So I'm giving you just the body.
IF :NEW.STAJYEAR!=:OLD.STAJYEAR THEN
INSERT INTO X_STAJ (USERID,EDITDATE,CHANGEDCOLUMN,OLDVALUE,NEWVALUE)
VALUES (:NEW.USERID,SYSDATE,'STAJYEAR',:OLD.STAJYEAR,:NEW.STAJYEAR);
END IF;
the error code is :ORA-04098: trigger 'SYS.TR__TRACK_CHANGES' is invalid and failed re-validation
CREATE OR REPLACE TRIGGER STAJCHANGER.TR_TRACK_CHANGES
AFTER UPDATE
OF STAJYEAR
,STAJMONTH
,STAJDAY
ON STAJCHANGER.STAJ
REFERENCING NEW AS New OLD AS Old
FOR EACH ROW
DECLARE
OLDVALUE NUMBER;
NEWVALUE NUMBER;
COLUMNID NUMBER;
BEGIN
IF :NEW.STAJYEAR!=:OLD.STAJYEAR THEN
INSERT INTO X_STAJ (USERID,EDITDATE,CHANGEDCOLUMN,OLDVALUE,NEWVALUE)
VALUES (:NEW.USERID,SYSDATE,'STAJYEAR',:OLD.STAJYEAR,:NEW.STAJYEAR);
END IF;
IF :NEW.STAJMONTH!=:OLD.STAJMONTH THEN
INSERT INTO X_STAJ (USERID,EDITDATE,CHANGEDCOLUMN,OLDVALUE,NEWVALUE)
VALUES (:NEW.USERID,SYSDATE,'STAJMONTH',:OLD.STAJMONTH,:NEW.STAJMONTH);
END IF;
IF :NEW.STAJDAY!=:OLD.STAJDAY THEN
INSERT INTO X_STAJ (USERID,EDITDATE,CHANGEDCOLUMN,OLDVALUE,NEWVALUE)
VALUES (:NEW.USERID,SYSDATE,'STAJDAY',:OLD.STAJDAY,:NEW.STAJDAY);
END IF;
END TR_TRACK_CHANGES;
/
The error appears to indicates that the trigger owner is SYS, but the creation statement you show explicitly gives the owner as STAJCHANGER.
This makes me wonder, did you accidentally create an (invalid) version of the trigger in SYS at some point, and forget to drop it?
This SQL Plus command will show the error:
SHOW ERROR TRIGGER STAJCHANGER.TR_TRACK_CHANGES