mysql中的存储过程能返回数组么
mysql中要获得存储过程的返回值,可以增加一个out参数,用来返回。
mysql中存储过程的例子:
CREATE PROCEDURE addvoucher (
IN userid INT,
IN voucherid INT,
OUT result INT
)
BEGIN
SELECT
@endate_a := endate ,@batch_a := batch ,@c_count_a := c_count,
@isdead_a := isdead
FROM
t_voucher
WHERE
id = voucherid;
SET autocommit = 0;
IF EXISTS (
SELECT
*
FROM
t_user_voucher tuv,
t_voucher tv
WHERE
tv.id = tuv.voucherid
AND tv.batch =@batch_a
) THEN
SET result = 1;-- 已存在
SELECT
result;
ELSE
IF @c_count_a > 0 THEN
IF (
TO_DAYS(@endate_a) - TO_DAYS(NOW())
) > 0 THEN
IF @isdead_a = 1 THEN
INSERT INTO t_user_voucher (userid, voucherid, isdead)
VALUES
(userid, voucherid, 1);
UPDATE t_voucher SET c_count = c_count-1 where id = voucherid;
SET result = 0;-- 成功
END;
下面是调用并返回结果: