Search code examples
mysqlsqlstored-proceduresaws-lambdaworkbench

MYSQL- Utilizing a Loop in a stored procedure


i have a stored procedure where I want to add 2 numbers. But in column Num1 I have same values with different Num2 values. I want to sum in a loop but this does not works. Please can someone review and update for my code below

CREATE DEFINER=`admin`@`%` PROCEDURE `Calculating_Stored_Procedure1`(
    IN Num2 VARCHAR(55), 
    IN Num1 VARCHAR(55),
    IN sum (55)
)
BEGIN       
    CALL mysql.lambda_async(
        'arn:aws:lambda:us-east-1:Test',
        CONCAT('{"Num1" : "', @Num1, '",  "Num2" : "', @Num2, '",  "Sum" : "', @Sum, '"}')
    );  
END

Solution

  • The best way is using a CURSOR inside the stored procedure. Worked like a charm for me.