我在postgresql数据库上有一个存储过程。当我尝试进行涉及类型转换的算术运算时,我遇到了问题。这是代码:
DECLARE
myVar DOUBLE PRECISION;
myVar2 DOUBLE PRECISION;
BEGIN
SELECT CAST((row1/row2) AS DOUBLE PRECISION) FROM myTable WHERE row3 = "value" INTO myVar;
--row1 and row2 type are integer type
myVar = myVar + (myVar*40)/200;
myVar2 = myVar * $2;
--$2 is an integer argument of function
--other squeryes
END
现在,在其余代码中我在INSERT查询中使用myVar2时,我数据库中添加的值为0.为什么?看起来我的操作错了......
答案 0 :(得分:1)
请尝试
SELECT CAST(row1 AS DOUBLE PRECISION)/row2)
FROM myTable
WHERE row3 = "value" INTO myVar;
让我知道它是否有效。
此致
Ashutosh Arya