Question: MySQL Workbench (Error Code: 1327. Undeclared variable: order_id) Just need to know why I am encountering this error in the following code; DROP PROCEDURE IF

MySQL Workbench (Error Code: 1327. Undeclared variable: order_id)

Just need to know why I am encountering this error in the following code;

DROP PROCEDURE IF EXISTS test; DELIMITER //

CREATE PROCEDURE test() BEGIN DECLARE sql_error TINYINT 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/2016', 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.';

END IF; END // DELIMITER ; call test();

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!