我正在制作一个学校项目的程序,如果它没有被使用,它会从课程表中删除一个特定的课程。
根据我读过的所有内容,这是正确的设置,但是在最后一个“结束”中是错误的。 表示如果有“缺失”的话
Delimiter // CREATE PROCEDURE DeleteCourse ( pCourseNumber varchar (7) ) BEGIN if NOT EXISTS(SELECT * FROM trackcourses WHERE courseNumber = pCourseNumber) then BEGIN DELETE FROM courses WHERE courseNumber = pCourseNumber; DELETE FROM restrictors WHERE courseNumber = pCourseNumber; select row_count(); END; else BEGIN return 'Course could not be deleted'; END; END; // <-- Syntax error: missing 'if'任何想法和想法都非常感谢!
谢谢,
奇怪的。
I'm making a procedure for a school project that removes a specific course from the course table if it's not in use.
According to everything I've read this is the correct setup but tere's an error on that last "END;" line that says there's a "missing 'if'"
Delimiter // CREATE PROCEDURE DeleteCourse ( pCourseNumber varchar (7) ) BEGIN if NOT EXISTS(SELECT * FROM trackcourses WHERE courseNumber = pCourseNumber) then BEGIN DELETE FROM courses WHERE courseNumber = pCourseNumber; DELETE FROM restrictors WHERE courseNumber = pCourseNumber; select row_count(); END; else BEGIN return 'Course could not be deleted'; END; END; // <-- Syntax error: missing 'if'Any thoughts and ideas are greatly appreciated!
Thanks,
Weird.
最满意答案
您可能需要在与IF相同的行上使用THEN ,并使用END IF而不是BEGIN END块。
IF <statement> THEN ... END IF请参阅这里了解MySQL语法
如果你只是使用:
... IF NOT EXISTS(SELECT * FROM trackcourses WHERE courseNumber = pCourseNumber) THEN DELETE FROM courses WHERE courseNumber = pCourseNumber; DELETE FROM restrictors WHERE courseNumber = pCourseNumber; select row_count(); ELSE RETURN 'Course could not be deleted'; END IF ...应该没问题
You may need to use the word THEN on the same line as the IF, and use END IF instead of BEGIN END blocks.
IF <statement> THEN ... END IFSee here for MySQL syntax
If you just use:
... IF NOT EXISTS(SELECT * FROM trackcourses WHERE courseNumber = pCourseNumber) THEN DELETE FROM courses WHERE courseNumber = pCourseNumber; DELETE FROM restrictors WHERE courseNumber = pCourseNumber; select row_count(); ELSE RETURN 'Course could not be deleted'; END IF ...It should be fine
更多推荐
发布评论