samedi 5 avril 2014

Can not understand why the error is


Vote count:

-1




I got an error code: 1327. Undeclared variable; order_id. I been looking at the code for hours, can not figure out where the error would. I thought it might link to 'Select last insert()..



USE Data_Name

DROP PROCEDURE IF EXISTS test;

DELIMITER //

PROCEDURE test()
BEGIN
DECLARE sql_error INT DEFAULT FALSE;

DECLARE CONTINUE HANDLER FOR SQLEXCEPTION
SET sql_error = TRUE;

START TRANSACTION;

INSERT INTO orders VALUES
(DEFAULT, 3, NOW(), '10.00', '0.00', NULL, 4,
'American Express', '378282246310005', '04/2013', 4);

SELECT LAST_INSERT_ID()INTO order_id;

INSERT INTO order_items VALUES
(DEFAULT, order_id, 6, '415.00', '161.85', 1);

INSERT INTO order_items VALUES
(DEFAULT, order_id, 1, '699.00', '209.70', 1);

IF sql_error = FALSE THEN
COMMIT;
SELECT 'The transaction was committed.';
ELSE
ROLLBACK;
SELECT 'The transaction was rolled back.';
END IF;
END//


asked 1 min ago






Aucun commentaire:

Enregistrer un commentaire