日期:2014-05-16  浏览次数:20780 次

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,函数不支持。

?