创建:
delimiter //
create procedure my_add(IN a int, IN b int, OUT c int)
begin
if a is null then set a = 0;
end if;
if b is null then set b = 0;
end if;
set c = a + b;
end;
//
delimiter ;
查看:
方法一:(直接查询,比较实用,查看当前自定义的存储过程)
select `specific_name` from mysql.proc where `db` = 'your_db_name' and `type` = 'procedure'
方法二:(查看数据库里所有存储过程+内容)
show procedure status;
方法三:(查看当前数据库里存储过程列表)
select specific_name from mysql.proc ;
方法四:(查看某一个存储过程的具体内容)
select body from mysql.proc where specific_name = 'your_proc_name';
查看存储过程或函数的创建代码 :
show create procedure your_proc_name;
show create function your_func_name;
调用:
mysql> set @a = 10;
Query OK, 0 rows affected (0.00 sec)
mysql> set @b = 20;
Query OK, 0 rows affected (0.00 sec)
mysql> set @c = 0;
Query OK, 0 rows affected (0.00 sec)
mysql>select @c;
+------+
| @c |
+------+
| 0 |
+------+
mysql> call my_add(@a, @b, @c);
Query OK, 0 rows affected (0.00 sec)
mysql> select @a, @b, @c;
+------+------+------+
| @a | @b | @c |
+------+------+------+
| 10 | 20 | 30 |
+------+------+------+
1 row in set (0.00 sec)
删除
drop procedure your_proc_name;
参考:http://www.111cn.net/database/mysql/35817.htm
http://blog.sina.com.cn/s/blog_594196850100laip.html
http://database.51cto.com/art/201006/203159.htm
http://blog.sina.com.cn/s/blog_52d20fbf0100ofd5.html