gpt4 book ai didi

mysql - 创建过程时出现语法错误

转载 作者:行者123 更新时间:2023-11-29 21:42:56 24 4
gpt4 key购买 nike

使用 Toad for MySQL,我在 CREATE PROCEDURE 语句的最后部分遇到错误,其中代码显示 END//。这是我的完整代码:

DELIMITER //
CREATE PROCEDURE spWHS_FundedYTD()
BEGIN
DECLARE fundedyear INT;
DECLARE fundedmonth INT;

SET fundedyear = 2000;
SET fundedmonth = 1;

WHILE fundedyear <= 2015 DO

BEGIN

WHILE fundedmonth <= 12 DO

BEGIN

SELECT CONCAT(a15.LastName, ', ' ,a15.FirstName) AS AE,
a11.LOS_Loan_Number__c,
a11.Funded_Date__c,
a11.Amount,
a11.Loan_Type__c,
a11.Purpose__c
FROM `Opportunity` a11
LEFT JOIN Account a12
ON (a11.AccountId = a12.Id)
LEFT JOIN `RecordType` a14
ON (a11.RecordTypeId = a14.Id)
LEFT JOIN `USER` a15
ON (a11.OwnerId = a15.Id)
WHERE a14.Name = 'Wholesale Loan'
AND YEAR(a11.Funded_Date__c) = 2015
AND MONTH(a11.Funded_Date__c) = 4
AND a15.LastName = 'BADDE';

SET @fundedmonth = @fundedmonth + 1;

END WHILE;

SET @fundedmonth = 1;
SET @fundedyear = @fundedyear + 1;

END WHILE;

END //
DELIMITER ;

错误如下:

 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHILE;

SET @fundedmonth = 1;
SET @fundedyear = @fundedyear + 1;' at line 37 45 3

我不明白为什么会出现错误。有什么想法吗?

最佳答案

一段时间后你不需要开始。您的程序应该是:

DELIMITER //
CREATE PROCEDURE spWHS_FundedYTD()
BEGIN
DECLARE fundedyear INT;
DECLARE fundedmonth INT;

SET fundedyear = 2000;
SET fundedmonth = 1;

WHILE fundedyear <= 2015 DO

WHILE fundedmonth <= 12 DO

SELECT CONCAT(a15.LastName, ', ' ,a15.FirstName) AS AE,
a11.LOS_Loan_Number__c,
a11.Funded_Date__c,
a11.Amount,
a11.Loan_Type__c,
a11.Purpose__c
FROM `Opportunity` a11
LEFT JOIN Account a12
ON (a11.AccountId = a12.Id)
LEFT JOIN `RecordType` a14
ON (a11.RecordTypeId = a14.Id)
LEFT JOIN `USER` a15
ON (a11.OwnerId = a15.Id)
WHERE a14.Name = 'Wholesale Loan'
AND YEAR(a11.Funded_Date__c) = 2015
AND MONTH(a11.Funded_Date__c) = 4
AND a15.LastName = 'BADDE';

SET @fundedmonth = @fundedmonth + 1;

END WHILE;

SET @fundedmonth = 1;
SET @fundedyear = @fundedyear + 1;

END WHILE;

END //
DELIMITER ;

关于mysql - 创建过程时出现语法错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34344416/

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