CREATE TRIGGER hundert
AFTER INSERT ON Leistung
FOR EACH ROW MODE DB2SQL
WHEN(SELECT modulNR, SUM(Prozentanteil) AS summe
FROM Leistung
GROUP BY modulNr
HAVING SUM(prozentanteil) > 100)
BEGIN ATOMIC
SIGNAL SQLSTATE '23506'
SET MESSAGE_TEXT = ('The Sum is bigger then 100');
END
如果我想说如果总和大于100则必须检查所有“prozentanteil”,如何创建WHEN语句?
答案 0 :(得分:1)
如果查看手册中CREATE TRIGGER
语句的语法图,您将看到WHEN
子句需要一个返回布尔值的搜索条件。子选择本身不能返回布尔值。您可能打算在那里使用EXISTS
谓词:
...
WHEN EXISTS (SELECT ...)
...