简体   繁体   中英

Procedure to change auto_increment value on table

I want write procedure which after execute another procedure change auto increment value in my table. Problem is procedure created ,but not works. When i try to run i have error #1210 - Incorrect arguments to EXECUTE. I find similar problem in link : Set AUTO_INCREMENT value through variable in MySql ,but it's not working for me.

I try change @v_value for v_value (normal variable, not @variable). Also I try use '?' in @v_sql but not working too. I try change 'READS SQL DATA' but no matter. Help what's going wrong.

DELIMITER //
CREATE PROCEDURE check_increment_value()
READS SQL DATA
BEGIN
SET @v_value = (SELECT MAX(id_version)+1 FROM versions);
SET @v_sql = CONCAT('ALTER TABLE `wersje` AUTO_INCREMENT = ',@v_value);
PREPARE st FROM @v_sql;
EXECUTE st USING @v_value;
END
//

Thanks for your help :)

您通过字符串插值而不是通过prepared语句传递参数,因此不需要指定using子句:

EXECUTE st;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM