据我从其他答案中了解到的,我们不能在准备好的语句中使用局部变量。由于用户变量没有类型,我们如何将语句的结果存储在十进制中?
下面的代码将将结果转换为整数。
set @mypenetration = null;
set @sql = 'select max(penetration) into ? from (select penetration from fssector2 where penetration > 0 order by penetration asc LIMIT ? ) as MyResult ;';
prepare stm1 from @sql;
execute stm1 using @myPenetration, @a;
SELECT @mypenetration;我怎么能从中得到小数点呢?
发布于 2015-10-05 12:50:29
您可以在查询中直接使用用户定义的变量:
set @mypenetration = null;
set @sql = 'select CONVERT(max(penetration), DECIMAL(10,2)) into @mypenetration from (select penetration from fssector2 where penetration > 0 order by penetration asc LIMIT ? ) as MyResult ;';
prepare stm1 from @sql;
execute stm1 using @a;
SELECT @mypenetration;例如,您还可以使用CONVERT()将值转换为十进制(10,2)。
https://stackoverflow.com/questions/32948760
复制相似问题