1
我有一個存儲過程,如下所示。Mysql存儲過程獲取數據並返回爲行
在這個過程中,查詢應該返回一個基於名稱匹配的行;但是當我嘗試使用此SR時,查詢不會提取,並且SR未成功執行。請讓我知道我的錯誤?
DROP TABLE TEMP;
CREATE TABLE TEMP
(
NAME VARCHAR(15)
);
INSERT INTO TEMP (SELECT DISTINCT(NAME) FROM IMDETAILS);
DELIMITER $$
CREATE PROCEDURE INCIDENT()
BEGIN
DECLARE NAMEE VARCHAR(10);
DECLARE CUR1 CURSOR for SELECT NAME FROM TEMP;
open CUR1;
read_loop: LOOP
FETCH CUR1 INTO NAMEE;
SELECT NAMEE;
insert into incident values ((select distinct(NAME) from IMDETAILS where NAME=NAMEE),
(SELECT COUNT(*) FROM IMDETAILS WHERE NAME=NAMEE AND RESOLVED_DATE=(SELECT CURDATE()) AND STATUS='RESOLVED'),
(SELECT COUNT(*) FROM IMDETAILS WHERE NAME=NAMEE AND RESOLVED_WEEK = WEEK(CURDATE()) AND STATUS='RESOLVED'),
(SELECT COUNT(*) FROM IMDETAILS WHERE NAME=NAMEE AND RESOLVED_MONTH=(SELECT DATE_FORMAT(NOW(),'%M')) AND STATUS='RESOLVED'),
(SELECT POINTS FROM POINT WHERE IMCOUNT<=(SELECT COUNT(*) FROM IMDETAILS WHERE NAME=NAMEE AND RESOLVED_MONTH=(SELECT DATE_FORMAT(NOW(),'%M'))
AND STATUS='RESOLVED')));
END LOOP;
CLOSE CUR1;
END $$;
DELIMITER;
最後一個分隔符的說法應該是分隔符; –
您可以添加示例數據和調用語句嗎? –
我有IMDETAILS表的列名爲「名稱」,「每日計數」,「週末計數」,「每月計數」我臨時表的列爲「名稱」.so在我的商店程序中,臨時表中的名稱應該根據每天,每週,每月計數與IMDETAILS表中的名稱匹配。 – RMP