存储过程
先挖好坑= =
存储过程
建立:
#创建存储过程(查询得到男性或女性的数量, 如果传入的是 0 就女性否则是男性)
DELIMITER $
CREATE PROCEDURE student.ges_user_count(IN sex_id INT, OUT user_count INT) BEGIN
IF sex_id=0 THEN
SELECT COUNT(*) FROM student.p_user WHERE p_user.sex='女' INTO user_count; ELSE
SELECT COUNT(*) FROM student.p_user WHERE p_user.sex='男' INTO user_count; END IF;
END
$
调用:
DELIMITER ;
SET @user_count = 0;
CALL student.ges_user_count(1, @user_count);
SELECT @user_count;
问题:
ERROR 1436 (HY000): Thread stack overrun: 13440 bytes used of a 131072 byte stack, and 128000 bytes needed. Use 'mysqld --thread_stack=#' to specify a bigger stack.
原因:thread_stack过小
解决:
Mac下
vim /etc/my.cnf
Win下
修改 my.ini
用到的命令:
查看所有存储过程:
1.select 'name' from student.proc where db='db_name' and type='PROCEDURE'
2.show procedure status;
查看存储过程或函数的创建代码:
show create procedure proc_name;
show create function func_name;