gpt4 book ai didi

mysql - 我的程序查询

转载 作者:行者123 更新时间:2023-11-30 21:44:56 26 4
gpt4 key购买 nike

CREATE PROCEDURE driver_report (IN arg_year INT, IN arg_month INT)
BEGIN
DECLARE done INT DEFAULT 0;
DECLARE driver_iden INT DEFAULT 0
DECLARE M_o_w INT DEFAULT 0
DECLARE C1 CURSOR FOR
SELECT D_id, MonthR
FROM driver
JOIN report USING (D_id)
WHERE MonthR = arg_month
AND YearR = arg_year
GROUP BY D_id

DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET done=1

OPEN C1 cursor

WHILE (done = 0) DO
FETCH C1 INTO driver_iden, M_o_w
INSERT INTO Report3 ('R3_id', 'Driver_identification', 'Month_of_workD', 'Year_of_workD')
VALUES (NULL, d_id, arg_month, arg_year)
END WHILE

CLOSE C1 cursor
END;

当我尝试执行它时,它会提示这个 done INT DEFAULT 0 和这个 DECLARE driver_iden INT DEFAULT 0

它说是语法问题,但我不确定到底是哪里出了问题

CREATE PROCEDURE driver_report (IN arg_year INT, IN arg_month INT) BEGIN DECLARE done INT DEFAULT 0 错误代码:1064。您的 SQL 语法有误;查看与您的 MySQL 服务器版本对应的手册,了解在第 3 行的 '' 附近使用的正确语法

我需要在这个过程中使用光标

最佳答案

看起来你可以用一个查询来完成这项工作而不是序列化它:

CREATE PROCEDURE driver_report (IN arg_year INT, IN arg_month INT)
BEGIN
INSERT INTO Report3 ('R3_id', 'Driver_identification', 'Month_of_workD', 'Year_of_workD')
SELECT DISTINCT driver.D_id, MonthR
FROM driver
JOIN report USING (D_id)
WHERE MonthR = arg_month AND YearR = arg_year;
END

关于mysql - 我的程序查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49906887/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com