Home > Database > Mysql Tutorial > body text

Multiple select issues in mysql stored procedures

WBOY
Release: 2016-08-29 08:36:20
Original
1290 people have browsed it

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?

Reply content:

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>
Copy after login

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

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template