Both insert statements are successful and inserts correctly on table registration and registration_header. My only problem is, it does not return the correct id through the myOutParameter.
It's not picking up the value of @var_registrationId using SET myOutParameter = @var_registrationId
Is my syntax wrong? I know i can set it using SET
CREATE DEFINER=`root`@`localhost` PROCEDURE `register`(IN parameter1 INT, IN parameter2 INT, OUT myOutParameter INT)
BEGIN
DECLARE var_registrationId INT;
DECLARE EXIT HANDLER FOR sqlexception
BEGIN
ROLLBACK;
RESIGNAL;
END;
START TRANSACTION;
-- first insert to registration table which generates a Primary key auto increment id
INSERT INTO registration(col1,col2) VALUES (parameter1, parameter2);
SELECT LAST_INSERT_VALUE() INTO var_registrationId; -- id of insert on registration table
insert into registration_header(registrationId,column)
VALUES(@var_registrationId,parameter1);
-- the next statement is not assigning the value of var_registrationId to the myOutParameter using SET
SET myOutParameter = @var_registrationId; -- this isn't working and returns 0
COMMIT;
END
I don't know what's wrong.
I hope you can help.
Thanks in advance