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

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

WBOY
Release: 2016-06-01 13:08:45
Original
1129 people have browsed it

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

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

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

语法为CALL PROCEDURE_NAME() ,如:

CALL proc_demo()
Copy after login

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
Copy after login

然后调用存储过程

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

返回相应的结果







source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template