MySQL 练习题16.1

【MySQL 练习题16.1】少年辛苦终身事,莫向光阴惰寸功。这篇文章主要讲述MySQL 练习题16.1相关的知识,希望能为你提供帮助。
mysql 练习题16.1

MySQL 练习题16.1

文章图片

1…创建存储过程,使用流程控制语句,编写SQL语句,要求以下:
(1)实现1-10之间数字的遍历。
(2)当数字大于10退出遍历。
(3)数字在1-10之间时,遍历数字并输出。
mysql> delimiter // mysql> create procedure proc10() -> begin -> declare id int default 0; -> my_loop:loop -> set id=id+1; -> if id> 10 then leave my_loop; -> end if; -> select id; -> end loop my_loop; -> end //

mysql> create procedure proc10() -> begin -> declare i int default 1; -> while i< =10 do -> select i; -> set i=i+1; -> end while; -> end // Query OK, 0 rows affected (0.00 sec)

2…创建的学生表及数据,创建存储过程,定义两个变量,分别接收tom的成绩和性别,输出这两个变量,调用并删除存储过程
mysql> select * from student; +----+------+-------+--------+ | id | name | grade | gender | +----+------+-------+--------+ |1 | tom|60 | 男| |2 | jack |70 | 男| |3 | rose |90 | 女| |4 | lucy |100 | 女| +----+------+-------+--------+ 4 rows in set (0.00 sec)

mysql> delimiter // mysql> create procedure proc10() -> begin -> declare s_grade float; -> declare s_gender char(4); -> select grade,gender into s_grade,s_gender from student where name=tom; -> select s_grade,s_gender; -> end // Query OK, 0 rows affected (0.00 sec)mysql> call proc10() // +---------+----------+ | s_grade | s_gender | +---------+----------+ |60 | 男| +---------+----------+ 1 row in set (0.02 sec)Query OK, 0 rows affected (0.02 sec)


    推荐阅读