为了让它理解,我们使用名为“student_info”的表,它具有以下值 -
mysql> Select * from student_info;
+-----+---------+------------+------------+
| id | Name | Address | Subject |
+-----+---------+------------+------------+
| 101 | YashPal | Amritsar | History |
| 105 | Gaurav | Jaipur | Literature |
| 110 | Rahul | Chandigarh | History |
| 125 | Raman | Shimla | Computers |
+------+--------+------------+------------+
4 rows in set (0.00 sec)
登录后复制
现在,借助以下查询,我们将创建一个带有 IN 参数的存储过程,该过程将通过提供姓名作为参数来显示特定学生的所有详细信息。
mysql> DELIMITER // ;
mysql> Create PROCEDURE detail(IN S_Name VARCHAR(20))
-> BEGIN
-> SELECT * From Student_info WHERE Name = S_Name;
-> END //
Query OK, 0 rows affected (0.16 sec)
mysql> DELIMITER ;
登录后复制
S_Name 是存储过程“detail”的 IN 参数。如果我们想查看学生姓名“Gaurav”的所有详细信息,则可以借助以下查询来完成 -
mysql> CALL detail('Gaurav');
+-----+--------+---------+------------+
| id | Name | Address | Subject |
+-----+--------+---------+------------+
| 105 | Gaurav | Jaipur | Literature |
+-----+--------+---------+------------+
1 row in set (0.00 sec)
Query OK, 0 rows affected (0.01 sec)
mysql> CALL detail('Raman');
+-----+-------+---------+-----------+
| id | Name | Address | Subject |
+-----+-------+---------+-----------+
| 125 | Raman | Shimla | Computers |
+-----+-------+---------+-----------+
1 row in set (0.00 sec)
Query OK, 0 rows affected (0.01 sec)
登录后复制
以上就是如何创建带有 IN 参数的 MySQL 存储过程?的详细内容,更多请关注每日运维网(www.mryunwei.com)其它相关文章!