mySQL 查询函数将小数成绩转换为字母成绩时出现语法错误
当我尝试在 MySQL 中创建一个函数将小数成绩转换为字母成绩时,我遇到了语法错误。
可能是什么问题?
错误 1064 (42000):您的 SQL 语法有错误;检查与您的 mySQL 服务器版本相对应的手册,了解在 'conv(gpa DOUBLE) 附近使用的正确语法 返回字符 开始
声明等级 CHAR;
SELECT CASE WHEN gp' 在第 1 行
这是我的代码:
delimiter $
CREATE FUNCTION conv(gpa DOUBLE)
RETURNS CHAR
BEGIN
DECLARE grade CHAR;
SELECT CASE WHEN gpa BETWEEN 3.5 AND 4.0 THEN 'A'
WHEN gpa BETWEEN 3.0 AND 3.4 THEN 'B'
WHEN gpa BETWEEN 2.5 AND 2.9 THEN 'C'
WHEN gpa BETWEEN 2.0 AND 2.4 THEN 'D'
ELSE 'F'
END INTO grade
RETURN grade;
END $
I'm having troubles with a syntax error when trying to create a function in MySQL to convert a decimal grade into a letter grade.
What could be the issue?
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 'conv(gpa DOUBLE)
RETURNS CHAR
BEGIN
DECLARE grade CHAR;
SELECT CASE WHEN gp' at line 1
Here is my code:
delimiter $
CREATE FUNCTION conv(gpa DOUBLE)
RETURNS CHAR
BEGIN
DECLARE grade CHAR;
SELECT CASE WHEN gpa BETWEEN 3.5 AND 4.0 THEN 'A'
WHEN gpa BETWEEN 3.0 AND 3.4 THEN 'B'
WHEN gpa BETWEEN 2.5 AND 2.9 THEN 'C'
WHEN gpa BETWEEN 2.0 AND 2.4 THEN 'D'
ELSE 'F'
END INTO grade
RETURN grade;
END $
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您在末尾处缺少一个分号:
此外,您可能不应该使用名称
conv
因为这已经意味着 其他内容。You're missing a semi-colon near the end:
Also, you probably shouldn't use the name
conv
as this is already means something else.