我在 Rhel Linux 上有一个 MariaDB 10.6 服务器,我想为表创建一个触发器。这是我的代码:
DELIMITER //
CREATE TRIGGER before_salary_update
BEFORE UPDATE ON Employee
FOR EACH ROW
BEGIN
DECLARE salary_change DECIMAL(10, 2);
-- Calculate the percentage change in salary
SET salary_change = (NEW.salary - OLD.salary) / OLD.salary * 100;
-- Check if the change is within the 10% threshold
IF salary_change > 10 OR salary_change < -10 THEN
SIGNAL SQLSTATE '45000'
SET MESSAGE_TEXT = 'Error: Salary change exceeds 10% limit.';
END IF;
END //
DELIMITER ;
当我使用分隔符运行代码时,我的终端会冻结,我必须使用 ctrl+c 来中断它。当我不使用分隔符执行它时,我收到此错误:
ERROR 1064 (42000) at line 1: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '' at line 1
我也尝试将其复制到 sql 文件中并从操作系统执行它。但我遇到了同样的问题。