触发器仍在工作,甚至输入了错误的输入

发布于 2025-02-04 04:37:39 字数 537 浏览 3 评论 0原文

我的问题是,即使我放了错误的字母,除了“ F”或“ M”外,触发器仍然更新。另外,即使我将“ F”或“ M”字母放在小写中,触发器仍然可以正常工作。如果输入不正确,我要如何使触发器不起作用?例如将错误的字母放在小写字母中。

这是我的代码:

CREATE TRIGGER trgAllowance -- trigger name
    BEFORE UPDATE
    ON tab_employee FOR EACH ROW
    BEGIN
        IF new.EmpGender = 'F' THEN
            SET new.SpecialAllowance = (new.Salary*0.2); /* Count the amount of Salary times by specific amount */
        ELSEIF new.EmpGender = 'M' THEN
            SET new.SpecialAllowance = (new.Salary*0.05);
        END IF;
    END 

My problem is, even i put the wrong alphabet other than 'F' or 'M', the trigger still updated. Also, even i put the 'F' or 'M' alphabet in lowercase, the trigger still function. how i want to make the trigger not function if the input is not correct? such as putting the wrong alphabet with lowercase.

here is my code :

CREATE TRIGGER trgAllowance -- trigger name
    BEFORE UPDATE
    ON tab_employee FOR EACH ROW
    BEGIN
        IF new.EmpGender = 'F' THEN
            SET new.SpecialAllowance = (new.Salary*0.2); /* Count the amount of Salary times by specific amount */
        ELSEIF new.EmpGender = 'M' THEN
            SET new.SpecialAllowance = (new.Salary*0.05);
        END IF;
    END 

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文