如何将列的值分配给变量?

时间:2017-07-08 12:09:27

标签: mysql variables

我想将BalanceAmount设置为变量但它返回一个空值。

Declare BalAmt as int;
SET BalAmt = (SELECT BalanceAmount FROM mstragentrecharge);
SELECT BalAmt

1 个答案:

答案 0 :(得分:0)

如果此代码来自功能或程序,请尝试以下

Declare BalAmt as int;

SELECT BalanceAmount into BalAmt  FROM mstragentrecharge);

SELECT BalAmt

或者,对于简单查询:

SET @BalAmt  := '';
SELECT @BalAmt  := `BalanceAmount ` FROM mstragentrecharge limit 1;
SELECT @BalAmt FROM mstragentrecharge;