0
DELIMITER //
CREATE PROCEDURE 'execute_transaction'(IN sql_text VARCHAR(8000))

BEGIN 
    DECLARE EXIT HANDLER FOR SQLEXCEPTION
    BEGIN
        Rollback;
        SELECT CONCAT(sql_text, 'is not valid');
    END;
    SET autocommit = 0;
    SET TRANSACTION ISOLATION LEVEL Serializable;

    START TRANSACTION;

    select * from customer where customer_id='A';
    select * from customer where customer_id='B';
    update customer set Name='alireza mohammadi' where customer_id='B';

    IF(@@session.error_count>0) THEN
        Rollback;
    ELSE
        COMMIT;
    END IF;
END;
//

Error:

Error Code: 1064. You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''execute_transaction'(IN sql_text VARCHAR(8000)) BEGIN DECLARE EXIT HANDLER F' at line 1

Miladfa7
  • 102
  • 1
  • 7
  • Simple typographical error **notice the quotes around execute_transaction** `CREATE PROCEDURE 'execute_transaction'(IN sql_text VARCHAR(8000))` those should not be there `CREATE PROCEDURE execute_transaction(IN sql_text VARCHAR(8000))` see [demo](https://www.db-fiddle.com/f/t8GdFWLSoGH2zhFPruSpdX/0) – Raymond Nijland Oct 20 '19 at 11:51
  • .. Also this question might be a duplication for [When to use single quotes, double quotes, and backticks in MySQL](https://stackoverflow.com/questions/11321491/when-to-use-single-quotes-double-quotes-and-backticks-in-mysql) as you used single quotes to escape a identifier – Raymond Nijland Oct 20 '19 at 11:52

0 Answers0