Home > Database > Mysql Tutorial > mysql 动态执行存储过程语句

mysql 动态执行存储过程语句

WBOY
Release: 2016-06-07 18:01:15
Original
1053 people have browsed it

MSSQL中动态执行sql语句可以使用EXEC()函数。MSSQL中也有类似的函数EXECUTE(),不过不同的是MYSQL中动态执行存储过程语句与MSSQL还是有区别的。

下面写一个给大家做参考啊
代码如下:
create procedure sp_find(pfind varchar(500)
BEGIN
DECLAR msql varchar(2000);
SET @MyQuery=Concat('select * from 表 where ',pfind);
PREPARE msql from @MyQuery;
EXECUTE msql;
END

注意一点的就是MYSQL中有好多已经定义好的函数可以使用,比如上面的拼接函数Concat(),利用好这些函数会有很多帮助的。

Related labels:
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