Domanda

Ho creato un trigger simile al seguente:

delimiter //
CREATE TRIGGER update_total_seconds_on_phone AFTER INSERT
ON cdr 
FOR EACH ROW 
BEGIN
IF NEW.billsec > 0 AND NEW.userfield <> NULL THEN
UPDATE foo
SET total_seconds = total_seconds + NEW.billsec
WHERE phone_id = NEW.userfield;
END IF;

END;//

Sembra che vada bene. Tuttavia non sembra invocare quando ne ho bisogno. Ecco un esempio:

mysql> select total_seconds from foo where phone_id = 1;
+---------------+
| total_seconds |
+---------------+
|             0 | 
+---------------+
1 row in set (0.00 sec)

mysql gt &; inserire in cdr (billsec, userfield) VALUES (60, 1); Richiesta OK, 1 riga interessata, 12 avvisi (0,00 sec)

mysql> select total_seconds from foo where phone_id = 1;
+---------------+
| total_seconds |
+---------------+
|             0 | 
+---------------+

EDIT: gli avvisi in questo caso particolare non influiscono sul trigger. Sono principalmente colonne aggiuntive che non hanno valori predefiniti nella tabella cdr che causano gli avvisi. Per semplicità, ho tenuto la mia dichiarazione INSERT breve.

È stato utile?

Soluzione

Sono stati generati 12 avvisi. Cosa sono?

ETA: Oh, aspetta ... devi usare is not null anziché <> null. Qualsiasi confronto con null restituirà sempre <=>.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top