MySQL的存储过程declare语句报错游标示例
程序员文章站
2022-03-23 20:43:14
MySQL的存储过程declare语句报错游标示例
DELIMITER $$
CREATE DEFINER=`root`@`localhost`
PROCEDUR...
MySQL的存储过程declare语句报错游标示例
DELIMITER $$ CREATE DEFINER=`root`@`localhost` PROCEDURE `stu_ave_cursor_procedure`() BEGIN declare aveno char(11); declare avename char(10); declare avegrade float; drop table if exists fail_student; create table fail_student (aveno char(11), avename char(10), avegrade float); open stuave; while not flag do fetch stuave into aveno,avename,avegrade; declare avegrade float; declare flag int; declare stuave cursor for select student.sno,sname,avg(grade) from student,sc where student.sno=sc.sno group by student.sno; DECLARE CONTINUE HANDLER FOR NOT FOUND SET flag=1; set flag=0; fetch stuave into aveno,avename,avegrade; if (not flag) then if (avegrade<60) then insert into fail_student() values(aveno,avename,avegrade); end if; end if; end while; close stuave; END DELIMITER ;
DELIMITER $$ USE `student-course` $$ CREATE DEFINER=`root`@`localhost` PROCEDURE `cour_ave_cursor_procedure`() BEGIN declare aveno char(11); declare avename char(10); declare avegrade float; declare flag int; declare courave cursor for select course.cno,cname,avg(grade) from course,sc where course.cno=sc.cno group by course.cno; DECLARE CONTINUE HANDLER FOR NOT FOUND SET flag=1; set flag=0; drop table if exists `student-course`.fail_course; create table fail_course (aveno char(11),avename char(30), avegrade float); open courave; while not flag do fetch courave into aveno,avename,avegrade; if (not flag) then if (avegrade<70) then insert into fail_course() values(aveno,avename,avegrade); end if; end if; end while; close courave; END $$ DELIMITER ;
DELIMITER $$ DELIMITER ; 不写则会报错
不过到现在都没太明白,为什么 mysql 工具一定要个 delimiter
语法上是不需要 delimiter 就可以判断得出语句分割的,程序用 ODBC 提交多语
句的时候,这种东东就完全没有问题的,所以应该客户端工具稍微改进一下就可以>不要 delimiter 了吧
上一篇: JSP基本构成和执行过程