gpt4 book ai didi

mysql - 这个mysql语法有什么错误?

转载 作者:太空宇宙 更新时间:2023-11-03 10:50:16 24 4
gpt4 key购买 nike

我是 mysql 世界的新手。我正在尝试创建一个程序来根据他/她的 GPA 来决定学生的类(class)。我给了他们一个 CRegNo,它当时是 1 到 10。这是我的代码:

mysql> delimiter //
mysql> CREATE PROCEDURE DecideClass ()
-> BEGIN
-> DECLARE count INT;
-> DECLARE max INT;
-> SET count = 1;
-> SET max = 10;
-> DECLARE FClass CHAR(18) DEFAULT 'First class honors';
-> DECLARE sUpper CHAR(34) DEFAULT 'Second class honors-upper division';
-> DECLARE sLower CHAR(34) DEFAULT 'Second class honors-lower division';
-> DECLARE tClass CHAR(18) DEFAULT 'Third class honors';
-> WHILE count <= max DO
-> DECLARE GPA DECIMAL(3,2);
-> SET GPA = (SELECT GPA FROM STUDENT WHERE CRegNo = count);
-> IF GPA >= 3.7 THEN
-> UPDATE STUDENT SET Class = FClass WHERE CRegNo = count;
-> ELSE IF GPA < 3.7 AND GPA >= 3.3 THEN
-> UPDATE STUDENT SET Class = SUpper WHERE CRegNo = count;
-> ELSE IF GPA < 3.3 AND GPA >= 2.7 THEN
-> UPDATE STUDENT SET Class = SLower WHERE CRegNo = count;
-> ELSE IF GPA < 2.7 AND GPA >= 2.0 THEN
-> UPDATE STUDENT SET Class = TClass WHERE CRegNo = count;
-> END IF
-> SET count = count + 1;
-> END WHILE;
-> END;
-> //

然后它说

ERROR 1064 (42000): 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 'DECLARE FClass CHAR(18) DEFAULT 'First class honors'; DECLARE sUpper CHAR(34) DE' at line 7

有人可以帮我吗?错误是什么?

最佳答案

所有的 DECLARE 语句都必须在开头,在任何 SET 或任何其他内容之前。

关于mysql - 这个mysql语法有什么错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25771959/

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