mysql
There are multiple selects in the stored procedure, but I want to only return the last select as the result set. How to block other select outputs?
To get the return value of the stored procedure in mysql, you can add an out parameter to return.
Example of stored procedure in 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;-- already exists
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;--Success
END;
<code> </code>
This is not the result I want, your answer is wrong to my question
1) First of all, can you change the stored procedure? If you can just block the first few, then why query them if you don’t need them?
2) If you can't change it, the stupidest thing to do is to count the number of the selection you want, and then get the number of the result set in the returned result
First check whether the previous choices are necessary, and then we can think of solutions