Home >Database >Mysql Tutorial >MYSQL存储过程中表名使用变量_MySQL

MYSQL存储过程中表名使用变量_MySQL

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-06-01 13:29:591299browse

bitsCN.com

MYSQL存储过程中表名使用变量

 

#      该存储过程定义了几个传入参数,前缀都是para_

#      该存储过程的此部分功能是,查询根据传入参数动态生成的tbl_name表名的表中

 

SET  tbl_name = CONCAT("result_", para_user);SET @STMT := CONCAT("SELECT COUNT(*) INTO @num_count FROM ", tbl_name                      ," WHERE rng = '", para_rng                      ,"' AND north_latitude = ", para_north                      ," AND bck_datetime = '", para_datetime                      ,"' AND east_longitude = ", para_east, ";");  PREPARE STMT FROM @STMT;  EXECUTE STMT;

 

 

注:目前 存储过程 支持动态SQL,函数不支持。

bitsCN.com
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