MySQL 查询在 phpMyAdmin 事件调度程序中不起作用
MySQL query not working in phpMyAdmin Event Scheduler
我正在尝试 运行 查询:
SET @Curr_Weekday := DAYOFWEEK(CURRENT_DATE);
INSERT INTO daily_calibrations (`calibration_date`, `machine_ID`)
SELECT *
FROM
(
SELECT CURRENT_DATE, 37 FROM dual
UNION ALL
SELECT CURRENT_DATE, 38 FROM dual
UNION ALL
SELECT CURRENT_DATE, 39 FROM dual
UNION ALL
SELECT CURRENT_DATE, 40 FROM dual
UNION ALL
SELECT CURRENT_DATE, 41 FROM dual
UNION ALL
SELECT CURRENT_DATE, 42 FROM dual
UNION ALL
SELECT CURRENT_DATE, 43 FROM dual
UNION ALL
SELECT CURRENT_DATE, 44 FROM dual
UNION ALL
SELECT CURRENT_DATE, 48 FROM dual
UNION ALL
SELECT CURRENT_DATE, 49 FROM dual
) tmp
WHERE @Curr_Weekday <> 1
当我从 phpMyAdmin 控制台 运行 时它工作正常,正在添加所有行但是由于某种原因当我尝试将其安排为事件时我收到错误:
MySQL 说:#1064 - 你的 SQL 语法有误;查看与您的 MySQL 服务器版本对应的手册,了解在 'INSERT INTO daily_calibrations (calibration_date
, machine_ID
) 附近使用的正确语法
SELECT * FRO' 在第 3 行
解决了(感谢您的帮助@Shadow)
DELIMITER $$
CREATE DEFINER=`root`@`localhost`
EVENT `add_daily_calib`
ON SCHEDULE EVERY 1 DAY STARTS '2017-10-25 00:01:00'
ON COMPLETION PRESERVE ENABLE
COMMENT 'Add calibrations everyday'
DO
BEGIN
SET @Curr_Weekday := DAYOFWEEK(CURRENT_DATE);
INSERT INTO daily_calibrations (`calibration_date`, `machine_ID`)
SELECT *
FROM
(
SELECT CURRENT_DATE, 37 FROM dual
UNION ALL
SELECT CURRENT_DATE, 38 FROM dual
UNION ALL
SELECT CURRENT_DATE, 39 FROM dual
UNION ALL
SELECT CURRENT_DATE, 40 FROM dual
UNION ALL
SELECT CURRENT_DATE, 41 FROM dual
UNION ALL
SELECT CURRENT_DATE, 42 FROM dual
UNION ALL
SELECT CURRENT_DATE, 43 FROM dual
UNION ALL
SELECT CURRENT_DATE, 44 FROM dual
UNION ALL
SELECT CURRENT_DATE, 48 FROM dual
UNION ALL
SELECT CURRENT_DATE, 49 FROM dual
) tmp
WHERE @Curr_Weekday <> 1;
END $$
我已经通过 phpMyAdmin 控制台创建了事件。当我查看事件定义时,它会删除 DEMILITER $$
和 END $$
部分,但我已经对其进行了测试并且工作正常。
我正在尝试 运行 查询:
SET @Curr_Weekday := DAYOFWEEK(CURRENT_DATE);
INSERT INTO daily_calibrations (`calibration_date`, `machine_ID`)
SELECT *
FROM
(
SELECT CURRENT_DATE, 37 FROM dual
UNION ALL
SELECT CURRENT_DATE, 38 FROM dual
UNION ALL
SELECT CURRENT_DATE, 39 FROM dual
UNION ALL
SELECT CURRENT_DATE, 40 FROM dual
UNION ALL
SELECT CURRENT_DATE, 41 FROM dual
UNION ALL
SELECT CURRENT_DATE, 42 FROM dual
UNION ALL
SELECT CURRENT_DATE, 43 FROM dual
UNION ALL
SELECT CURRENT_DATE, 44 FROM dual
UNION ALL
SELECT CURRENT_DATE, 48 FROM dual
UNION ALL
SELECT CURRENT_DATE, 49 FROM dual
) tmp
WHERE @Curr_Weekday <> 1
当我从 phpMyAdmin 控制台 运行 时它工作正常,正在添加所有行但是由于某种原因当我尝试将其安排为事件时我收到错误:
MySQL 说:#1064 - 你的 SQL 语法有误;查看与您的 MySQL 服务器版本对应的手册,了解在 'INSERT INTO daily_calibrations (calibration_date
, machine_ID
) 附近使用的正确语法
SELECT * FRO' 在第 3 行
解决了(感谢您的帮助@Shadow)
DELIMITER $$
CREATE DEFINER=`root`@`localhost`
EVENT `add_daily_calib`
ON SCHEDULE EVERY 1 DAY STARTS '2017-10-25 00:01:00'
ON COMPLETION PRESERVE ENABLE
COMMENT 'Add calibrations everyday'
DO
BEGIN
SET @Curr_Weekday := DAYOFWEEK(CURRENT_DATE);
INSERT INTO daily_calibrations (`calibration_date`, `machine_ID`)
SELECT *
FROM
(
SELECT CURRENT_DATE, 37 FROM dual
UNION ALL
SELECT CURRENT_DATE, 38 FROM dual
UNION ALL
SELECT CURRENT_DATE, 39 FROM dual
UNION ALL
SELECT CURRENT_DATE, 40 FROM dual
UNION ALL
SELECT CURRENT_DATE, 41 FROM dual
UNION ALL
SELECT CURRENT_DATE, 42 FROM dual
UNION ALL
SELECT CURRENT_DATE, 43 FROM dual
UNION ALL
SELECT CURRENT_DATE, 44 FROM dual
UNION ALL
SELECT CURRENT_DATE, 48 FROM dual
UNION ALL
SELECT CURRENT_DATE, 49 FROM dual
) tmp
WHERE @Curr_Weekday <> 1;
END $$
我已经通过 phpMyAdmin 控制台创建了事件。当我查看事件定义时,它会删除 DEMILITER $$
和 END $$
部分,但我已经对其进行了测试并且工作正常。