SQL 触发器不起作用(根据时间表)
SQL Trigger doesn't work (based on schedule)
我想创建一个触发器,允许插入在工作时间(周一至周五上午 9 点至下午 5 点)执行。我目前有这个
CREATE DEFINER=`root`@`localhost` TRIGGER `noWorkHour`
BEFORE INSERT ON `empleado` FOR EACH ROW
BEGIN
IF DAYOFWEEK(NOW()) BETWEEN (2, 6)
AND CURTIME() BETWEEN '09:00:00' AND '17:00:00'
THEN
SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = 'Solo se pueden ingresar en horario de trabajo';
END IF;
END
但是当我尝试插入一些东西时,它显示:
/* Error de SQL (1241): Operand should contain 1 column(s) */
/* Affected rows: 0 Filas encontradas: 0 Advertencias: 0 Duración para 0 of 1 query: 0,000 sec. */
我为此使用 MariaDB。
@mustaccio 发表评论后,我在搞乱其他事情,而不是触发器本身。
触发器如下:
CREATE DEFINER=`root`@`localhost` TRIGGER `noWorkHour` BEFORE INSERT ON `empleado` FOR EACH ROW BEGIN
IF DAYOFWEEK(NOW()) NOT BETWEEN 2 AND 6 AND CURTIME() NOT BETWEEN '09:00:00' AND '16:00:00' THEN
SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = 'Solo se pueden ingresar en horario de trabajo';
END IF;
END
我想创建一个触发器,允许插入在工作时间(周一至周五上午 9 点至下午 5 点)执行。我目前有这个
CREATE DEFINER=`root`@`localhost` TRIGGER `noWorkHour`
BEFORE INSERT ON `empleado` FOR EACH ROW
BEGIN
IF DAYOFWEEK(NOW()) BETWEEN (2, 6)
AND CURTIME() BETWEEN '09:00:00' AND '17:00:00'
THEN
SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = 'Solo se pueden ingresar en horario de trabajo';
END IF;
END
但是当我尝试插入一些东西时,它显示:
/* Error de SQL (1241): Operand should contain 1 column(s) */
/* Affected rows: 0 Filas encontradas: 0 Advertencias: 0 Duración para 0 of 1 query: 0,000 sec. */
我为此使用 MariaDB。
@mustaccio 发表评论后,我在搞乱其他事情,而不是触发器本身。
触发器如下:
CREATE DEFINER=`root`@`localhost` TRIGGER `noWorkHour` BEFORE INSERT ON `empleado` FOR EACH ROW BEGIN
IF DAYOFWEEK(NOW()) NOT BETWEEN 2 AND 6 AND CURTIME() NOT BETWEEN '09:00:00' AND '16:00:00' THEN
SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = 'Solo se pueden ingresar en horario de trabajo';
END IF;
END