ORA-04079: invalid trigger specification in this code - oracle

Create trigger ittriggs before insert of salary on itempls for each row
The above code is to create a trigger that prices and user define error message and does not allow insertion
I couldn't create trigger using this code i don't know what mistake is in it

Related

How to write trigger in sql

I have condition to insert record in table for that i want to write trigger.
For an instance : when A code is getting inserted in the table at the same time insert B code as well in that table.
Need trigger query

If a trigger on an Oracle DB table fails to execute successfully or does not compile, can it impact the base table?

let's say there are tables a and b.
There is an AFTER INSERT trigger on a, that copies the row data to b.
If, during the execution of the trigger, there is an error does it impact table a in any way?
If the trigger does not compile, because it's ill-defined, does it impact table a?
I want to add a trigger to a table that is 'not mine'. I want to evaluate the risk that this can potentially pose.
Cheers
============== edit ================
I verified that - by handling the error (as suggested in the reply) - it now does not impact the base table.
create table tableA (column1 number);
create table tableB (column1 number, CONSTRAINT constraintName PRIMARY KEY (column1));
create or replace TRIGGER tableA_trigger
AFTER INSERT ON tableA
FOR EACH ROW
DECLARE
--
BEGIN
insert into tableB values (1);
EXCEPTION
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE('Error occured but ignored.');
END;
insert into tableA values (1);
insert into tableA values (1);
After that, tableA had two records, tableB only 1.
Without the exception handling, both tables would only have one record each, and after the first insert it would have shown an exception in the SQL Developer window.
Yes, it will impact the base table.
If there is error in insert trigger it will not allow to insert any record in base table. Same applies to all type of triggers.
Also, Adding DML triggers to tables affects the performance of DML statements on those tables.
According to oracle documentation:
If a predefined or user-defined error condition or exception is raised
during the execution of a trigger body, then all effects of the
trigger body, as well as the triggering statement, are rolled back
(unless the error is trapped by an exception handler). Therefore, a
trigger body can prevent the execution of the triggering statement by
raising an exception. User-defined exceptions are commonly used in
triggers that enforce complex security authorizations or integrity
constraints.

SQL trigger overwrites data in the column

I have a problem with trigger created to invoke before insert method.
For example, i have 3 columns in my table and 1 of these columns is inserted by trigger.
When i want to insert all data(into all columns) by myself trigger overwrites data in specified column.
The trigger is specified to invoke before insert command so i though that insert command will overwrite data in column specified in trigger.
Do anyone know how to solve this issue?
Is this possible for me to insert all data by myself when i have created a trigger?

How do I alter a trigger in Oracle?

I am trying to change the trigger script for my database. My trigger name is ARCH_USER_UPD_TRG and this puts any updates or deletes on the USER table into a Z_USER table
I am dropping a column from the USER table and now need to modify the trigger script to no longer use this column.
How do I modify the PL/SQL script of an oracle trigger?
A trigger is similar to a package or a procedure, so you can simply use
create or replace trigger triggerName
...
declare
...
begin
...
end;
The easy solution would be to Drop and Create the trigger once again with the modified SQL script code.
DROP TRIGGER ARCH_USER_UPD_TRG;
CREATE TRIGGER ARCH_USER_UPD_TRG
//rest of code body

After Trigger execute before constraint check in oracle

I have After Insert/Update trigger on Table T1 which get the referential data for Col1 from T2 and does some work and insert it into another table.
The col1 is FK to Table T2.
When user insert the incorrect or non existing value into the Col1 and if trigger is disabled I am getting constraint error that is fine.
But when trigger is enabled and user insert the wrong value in Col1 trigger is getting fired and shows the 'no data found' error message.
Actually I am expecting the table to throw constraint error, but trigger is throwing it.
Please let me know your comments about this trigger behaviour.
You do not mention whether you are using BEFORE or AFTER triggers. Please check the documentation for the order of execution:
BEFORE statement
BEFORE row
CONSTRAINTS
AFTER row
AFTER statement
I'm guessing the trigger would have to be a BEFORE trigger. It will run prior to the constraints being checked. If the trigger raises NO_DATA_FOUND, then the constraint never gets checked. If the trigger is disabled, it is not run, so the constraint gets checked.

Resources