Mysql stored procedure is not returning any out put wnen execute as a stored procedure. but when i execute as separate sql statement for every out parameter its returning output . can u please help me the reason as i am new to this mySQL .
DELIMITER $$
CREATE DEFINER=`root`@`localhost` PROCEDURE `ShopBusinessFunctions`(IN `shopid` VARCHAR(15), OUT `referalcount` INT, OUT `starscount` INT, OUT `WalletBalance` DECIMAL(10,2), OUT `TodaysBusiness` DECIMAL(10,2), OUT `CurMonthBusiness` DECIMAL(10,2), OUT `CurYearBusiness` DECIMAL(10,2))
BEGIN
DECLARE v_done INT DEFAULT FALSE;
DECLARE v_idRoom INT;
DECLARE v_maxAvailable INT;
DECLARE walletamount DECIMAL(10,2);
DECLARE toozocommission DECIMAL(10,2);
DECLARE WALLETBALANCE DECIMAL(10,2);
SELECT walletamount = sum(Amount) FROM shopswallet where shopid=shopid and isapproved =1;
SELECT toozocommission = sum(Amount) FROM shopspurchasewallet where shopid=shopid;
set WalletBalance = walletamount - toozocommission ;
select TodaysBusiness = sum(Amount) from shopspurchasewallet
where date_format(date_entered, '%Y-%m-%d') = date_format(now(), '%Y-%m-%d') and shopid=shopid;
select CurMonthBusiness = sum(Amount) from shopspurchasewallet
where date_format(date_entered, '%Y-%m') = date_format(now(), '%Y-%m') and shopid=shopid;
select CurYearBusiness = sum(Amount) from shopspurchasewallet
where date_format(date_entered, '%Y') = date_format(now(), '%Y') and shopid=shopid;
select count(ReferalID) from shops where ReferalID= shopid;
select starscount = count(starratings) from customerpurchaseentry where shopid =shopid;
END$$
DELIMITER ;
When i execute as single sql statement for each output parameter its returning output .
Plese help me to solve this issue .
2
Answers
Instead of using OUT parameters, you can return the values in a result set. Also, instead of using
SELECT variable = COUNT(*)
you should useSELECT COUNT(*) into variable
.Here is a procedure with the fixes:
And you can call the procedure and fetch the results:
The
$results
will then hold the result for the procedure.No
DECLAREs are needed. That outer
SELECThas no FROM
.Then, expect the
CALL
to return a single 6-column row.