如何 mysql 存储过程返回值
1个回答
展开全部
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;
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;
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |