时间:2021-07-01 10:21:17 帮助过:87人阅读
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