SQL触发器不起作用(基于计划)

时间:2016-08-23 19:25:49

标签: mysql sql triggers mariadb database-trigger

我想创建一个触发器,允许插入在工作时间执行(周一至周五上午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。

1 个答案:

答案 0 :(得分:0)

在@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