我有触发器,如下例所示:
BEFORE UPDATE ON icharts_user_stats FOR EACH ROW BEGIN
IF (NEW.col1> OLD.col1
OR NEW.col2 > OLD.col2) THEN
SET NEW.col3 = NEW.col3+1;
SET NEW.col4 = NEW.col4+1; END IF;
IF (NEW.col5> OLD.col5
OR NEW.col6 > OLD.col6) THEN
SET NEW.col7 = NEW.col7+1; END IF;
IF (NEW.col8> OLD.col8
OR NEW.col9 > OLD.col9) THEN
SET NEW.col10 = NEW.col10+1; END IF;
这类似于switch语句,在任何时候只会执行一个'if'。上面的代码有效,但是如果第一个'if'被击中,它仍将通过所有其他ifs。
由于
答案 0 :(得分:0)
你试过这个吗?
BEFORE UPDATE ON icharts_user_stats FOR EACH ROW BEGIN
IF (NEW.col1> OLD.col1
OR NEW.col2 > OLD.col2) THEN
SET NEW.col3 = NEW.col3+1;
SET NEW.col4 = NEW.col4+1;
ELSEIF (NEW.col5> OLD.col5
OR NEW.col6 > OLD.col6) THEN
SET NEW.col7 = NEW.col7+1;
ELSEIF (NEW.col8> OLD.col8
OR NEW.col9 > OLD.col9) THEN
SET NEW.col10 = NEW.col10+1; END IF;
答案 1 :(得分:0)
试试这个。
BEFORE UPDATE ON icharts_user_stats FOR EACH ROW
icharts_user_stats:BEGIN
IF (NEW.col1> OLD.col1
OR NEW.col2 > OLD.col2) THEN
SET NEW.col3 = NEW.col3+1;
SET NEW.col4 = NEW.col4+1;
leave icharts_user_stats;
END IF;
IF (NEW.col5> OLD.col5
OR NEW.col6 > OLD.col6) THEN
SET NEW.col7 = NEW.col7+1;
leave icharts_user_stats;
END IF;
IF (NEW.col8> OLD.col8
OR NEW.col9 > OLD.col9) THEN
SET NEW.col10 = NEW.col10+1;
leave icharts_user_stats;
END IF;