语法
CREATE [DEFINER = { user | CURRENT_USER }]
PROCEDURE sp_name ([proc_parameter[,...]])
[characteristic ...] routine_body
proc_parameter: [ IN | OUT | INOUT ] param_name type
type:
Any valid MySQL data type
characteristic:
COMMENT 'string'
| LANGUAGE SQL
| [NOT] DETERMINISTIC
| { CONTAINS SQL | NO SQL | READS SQL DATA
| MODIFIES SQL DATA }
| SQL SECURITY { DEFINER | INVOKER }
routine_body:
Valid SQL routine statement
登录后复制
Example
以下是一个示例,我们创建了一个简单的过程,从表格 ‘student_info’ 中获取所有记录,这些记录具有以下数据 −
mysql> select * from student_info;
+-----+---------+------------+------------+
| id | Name | Address | Subject |
+-----+---------+------------+------------+
| 100 | Aarav | Delhi | Computers |
| 101 | YashPal | Amritsar | History |
| 105 | Gaurav | Jaipur | Literature |
| 110 | Rahul | Chandigarh | History |
+------+--------+------------+------------+
4 rows in set (0.00 sec)
登录后复制
现在,通过以下查询,我们创建了名为allrecords()的存储过程
mysql> Delimiter //
mysql> Create Procedure allrecords()
-> BEGIN
-> Select * from Student_info;
-> END//
Query OK, 0 rows affected (0.02 sec)
mysql> DELIMITER ;
登录后复制
以上就是存储过程是什么,我们如何创建MySQL存储过程?的详细内容,更多请关注每日运维网(www.mryunwei.com)其它相关文章!