Warning: count(): Parameter must be an array or an object that implements Countable in /membri/oraclefaq/qa-include/app/format.php on line 384
Inserire un trigger after insert - Oracle FAQ - Il forum italiano su oracle
0 voti
2.4k visite
quesito posto in SQL e PLSQL da (150 punti)
modificato da

Ciao a tutti,
devo creare un trigger (after insert) su una tabella Oracle. La condizione è questa:
SE campo1 = 'x' AND campo2 is NULL AND campo3 is NOT NULL THEN campo2 = campo3 

ho provato a creare il trigger in questo modo:

CREATE OR REPLACE TRIGGER TR_oper
AFTER INSERT ON tabella1 FOR EACH ROW
BEGIN


IF :NEW.campo1= 'x'
AND :NEW.campo2 IS NULL AND :NEW.campo3 IS NOT NULL
THEN UPDATE tabella1 SET campo2 = campo3;
END IF;

END;

la compilazione viene effettuata ma se provo ad effettuare una insert nella tabella mi da errore:

ORA-04091: table tabella1 is mutating, trigger/function may not see it
ORA-06512: at "campo3", line 5
ORA-04088: error during execution of trigger 'tr_oper'
ORA-06512: at line 1
dove sbaglio?

1 Risposta

0 voti
risposta inviata da (2.4k punti)
modificato da
Questo problema come riporta l'errore è quello delle tabelle mutanti. Semplicemente non ti è permesso nel trigger modificare la stessa tabella e campo in cui stai eseguendo la DML.

Il consiglio è quello di spostare tutta la logica in una stored procedure che si occupa poi di fare la insert nella tabella di destinazione.

Domande correlate


Warning: count(): Parameter must be an array or an object that implements Countable in /membri/oraclefaq/qa-include/app/format.php on line 384

Warning: count(): Parameter must be an array or an object that implements Countable in /membri/oraclefaq/qa-include/app/format.php on line 384

Warning: count(): Parameter must be an array or an object that implements Countable in /membri/oraclefaq/qa-include/app/format.php on line 384

Warning: count(): Parameter must be an array or an object that implements Countable in /membri/oraclefaq/qa-include/app/format.php on line 384

Warning: count(): Parameter must be an array or an object that implements Countable in /membri/oraclefaq/qa-include/app/format.php on line 384
0 voti
1 risposta 1.6k visite
quesito posto 11 Settembre 2018 in SQL e PLSQL da niroantonio (120 punti)
0 voti
1 risposta 2.6k visite
quesito posto 5 Aprile 2018 in SQL e PLSQL da gr_g (150 punti)
0 voti
1 risposta 15k visite
0 voti
0 risposte 982 visite
0 voti
0 risposte 3.2k visite
...