我创建了以下存储过程,并且在我的生活中,我不明白为什么会出现上述错误。我尝试移动END //斜线越来越远,我添加了一个;之前 // 我做错了什么?
DELIMITER //
CREATE PROCEDURE ETL10501(TableStartPointer TIMESTAMP, TableWindowPointer TIMESTAMP)
BEGIN
DECLARE RowsExtractedCnt INT;
DECLARE RowsExtractedMaxID INT;
DECLARE RowsInsertedMaxID INT;
DECLARE InsertedRowCount INT;
DECLARE tmpTableWindowPointer TIMESTAMP;
SELECT RowsExtractedCnt = COUNT(*), RowsExtractedMaxID = MAX(ID) FROM tbl10501Raw
WHERE tbl10501Raw.DeviceReportedTime = tbl10501Raw.ReceivedAt
AND tbl10501Raw.DeviceReportedTime BETWEEN TableWindowPointer AND TableStartPointer;
SELECT RowsInsertedMaxID = (SELECT MAX(RowsExtractedMaxID10501) FROM etlETLEventLog);
IF RowsExtractedMaxID IS NULL THEN SET RowsExtractedMaxID:=0;
IF RowsInsertedMaxID IS NULL THEN SET RowsInsertedMaxID:=0;
IF RowsExtractedMaxID > RowsInsertedMaxID THEN
SELECT tbl10501Raw.DeviceReportedTime INTO tmpTableWindowPointer FROM tbl10501Raw
WHERE RowsInsertedMaxID = (tbl10501Raw.ID + 1);
INSERT INTO tblLast7Days
(CustomerID, DeviceID, Message, Facility, Severity, DeviceReportedTime,
InfoUnitID, SysLogTag)
SELECT tbl10501Raw.CustomerID, etlDIMDeviceNumbers.DeviceID, tbl10501Raw.Message,
tbl10501Raw.Facility, tbl10501Raw.Severity, tbl10501Raw.DeviceReportedTime,
tbl10501Raw.InfoUnitID, tbl10501Raw.SyslogTag
FROM etlDIMDeviceNumbers, tbl10501Raw
WHERE tbl10501Raw.DeviceReportedTime = tbl10501Raw.ReceivedAt
AND tbl10501Raw.FromHostIP = etlDIMDeviceNumbers.DeviceIPAddress
AND tbl10501Raw.DeviceReportedTime BETWEEN tmpTableWindowPointer AND TableStartPointer;
SELECT InsertedRowCount = COUNT(*)
FROM etlDIMDeviceNumbers, tbl10501Raw
WHERE tbl10501Raw.DeviceReportedTime = tbl10501Raw.ReceivedAt
AND tbl10501Raw.FromHostIP = etlDIMDeviceNumbers.DeviceIPAddress
AND tbl10501Raw.DeviceReportedTime BETWEEN tmpTableWindowPointer AND
TableStartPointer;
UPDATE etlETLEventLog
SET RowsActualInserted10501 = InsertedRowCount,
RowsExtractedCnt10501 = RowsExtractedCnt,
RowsExtractedMaxID10501 = RowsExtractedMaxID
WHERE etlETLEventLog.TableStartPointer = TableStartPointer;
END IF;
END; //
DELIMITER ;
提前谢谢。
答案 0 :(得分:0)
非常感谢你们这么快帮助和帮助。
我在多次搜索后发现MySQL错误1604是语法错误。所以我开始删除代码,直到找到问题为止。
这两行:
IF RowsExtractedMaxID IS NULL THEN SET RowsExtractedMaxID:=0;
IF RowsInsertedMaxID IS NULL THEN SET RowsInsertedMaxID:=0;
不知何故在语法上不起作用。老实说,我不知道为什么。我继续使用变量将它们包含在主SELECT语句中。
SELECT IFNULL(RowsExtractedCnt = COUNT(*), 0), IFNULL(RowsExtractedMaxID = MAX(ID), 0)
FROM tbl10760Raw
WHERE tbl10760Raw.DeviceReportedTime = tbl10760Raw.ReceivedAt
AND tbl10760Raw.DeviceReportedTime
BETWEEN TableWindowPointer AND TableStartPointer;
SELECT IFNULL(RowsInsertedMaxID = (SELECT MAX(RowsExtractedMaxID10760) FROM etlETLEventLog), 0);
我希望有一天会遇到类似问题的人。