為了讓它理解,我們使用名為“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.92cms.cn其它相關文章!