I use DB2 and writing a trigger count version works but I can’t convert it to exists version. I will use exists version because of performance reasons. It is a insert after trigger.
it works
IF (SELECT COUNT(*) FROM table where field=NEW.field ) = 0 THEN
---------
END IF;--
it doesn’t work
IF NOT EXISTS (SELECT * FROM table where field=NEW.field ) THEN
---------------------
END IF;--
TRY THIS: ,AS
this syntax to run this code
You need to tell DB2 about the terminator you used !!
AND
–#SET TERMINATOR $
This will ser the terminator to $
To change the terminator in the CLP on the fly, the following syntax will set it back:
–#SET TERMINATOR