时间:2021-07-01 10:21:17 帮助过:59人阅读
至于执行sql 则需要 PREPARE sql1 FROM @sql1; EXECUTE sql1; 感觉也比MSSQL复杂。
DELIMITER $$ DROP PROCEDURE IF EXISTS simple_while$$ CREATE PROCEDURE simple_while(IN period_no VARCHAR(7), IN all_test_id TEXT, OUT return_count INT) BEGIN SET return_count=0; SET @i=0; SET @arraylength=1+(LENGTH(all_test_id) - LENGTH(REPLACE(all_test_id,‘,‘,‘‘))); WHILE @i<@arraylength DO SET @i=@i+1; SET @result = REVERSE(SUBSTRING_INDEX(REVERSE(SUBSTRING_INDEX(all_test_id,‘,‘,@i)),‘,‘,1)); SET @sql=CONCAT(‘Update test_‘,period_no,‘ Set is_cancel = 1 WHERE all_test_id = ‘,@result); PREPARE sql1 FROM @sql; EXECUTE sql1; SET return_count=return_count+ ROW_COUNT(); END WHILE; END$$ DELIMITER ;
mysql 字符串分割 和 动态执行拼接sql
标签:执行sql 字符串分割 string return key word bsp 字符串 mssql