1. 首页 > 笙耀百科 >

mysql循环执行sql语句(mysqlfor循环)

关于mysql循环执行sql语句,mysqlfor循环这个很多人还不知道,今天欣欣来为大家解答以上的问题,现在让我们一起来看看吧!

mysql循环执行sql语句(mysqlfor循环)mysql循环执行sql语句(mysqlfor循环)


1、select @a=DRClass1, @b=DRClass2, @c=DRClass3, @d=DRClass4, @e=DRClass5 from Teacher Where TeacherID = @TeacherID create table classname(classname char(50)) insert into classname (classname) values (@a) if (@b is not null) begin insert into classname (classname) values (@b) if (@c is not null) begin insert into classname (classname) values (@c) if (@d is not null) begin insert into classname (classname) values (@d) if (@e is not null) begin insert into classname (classname) values (@e) end end end end select * from classname 以上这些SQL语句能不能转成一个存储过程?我自己试了下 ALTER PROCEDURE Pr_GetClass @TeacherID int, @a char(50), @b char(50), @c char(50), @d char(50), @e char(50) as select @a=DRClass1, @b=DRClass2, @c=DRClass3, @d=DRClass4, @e=DRClass5 from Teacher Where TeacherID = @TeacherID DROP TABLE classname create table classname(classname char(50)) insert into classname (classname) values (@a) if (@b is not null) begin insert into classname (classname) values (@b) if (@c is not null) begin insert into classname (classname) values (@c) if (@d is not null) begin insert into classname (classname) values (@d) if (@e is not null) begin insert into classname (classname) values (@e) end end end end select * from classname 但是这样的话,这个存储过程就有6个变量,实际上应该只提供一个变量就可以了 主要的问题就是自己没搞清楚 @a,@b,@C,@d 等是临时变量,是放在as后面重新做一些申明的,而不是放在开头整个存储过程的变量定义。

2、 (标准化越来越近了):namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /> 实战SQL语句收集(不断更新中--) 前言:这里将我编程实践中遇到的有价值的sql语句一路记下来,一方面方便自己查用,一方面也夯实下即将遗忘的回忆。

3、整个过程中我会不断更新,直到不能再加为止,同时,这里只记录最实用的咚咚,不效仿学院派的那一套。

本文到这结束,希望上面文章对大家有所帮助。

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至836084111@qq.com 举报,一经查实,本站将立刻删除。

联系我们

工作日:9:30-18:30,节假日休息