Home >Database >Mysql Tutorial >MySQL存储过程的学习(二)_MySQL

MySQL存储过程的学习(二)_MySQL

WBOY
WBOYOriginal
2016-06-01 13:08:451126browse

在(一)中完成了对存储过程的增删改查,接下来学习下怎么使用存储过程

1.存储过程的调用(无参)

存储过程调用的时候使用的CALL

语法为CALL PROCEDURE_NAME() ,如:

CALL proc_demo()

2.存储过程的调用(带参)

语法为CALL PROCEDURE_NAME(参数列表),

首先创建一个带参的存储过程

CREATE PROCEDURE proc_demo(IN param_id INT, OUT countnumber INT)BEGINSELECT COUNT(*) FROM T_USER WHERE ID >= param_id; #SELECT COUNT(*) INTO countnumber FROM T_USER WHERE ID >= param_id; END

然后调用存储过程

#设置传入参数变量并赋值#SET @param_id = 11;#调用存储过程#CALL proc_demo(@param_id,@countnumber)#直接写参数调用CALL proc_demo(11, @countnumber);#查询结果#SELECT @countnumber;

返回相应的结果







Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn