可以使用MYSQL的预处理逻辑:https://dev.mysql.com/doc/refman/8.0/en/sql-syntax-prepared-statements.html 例如: prepare stmt from 'select * from student where sage = ?'; set @a=20; execute stmt using @a ; 每一次执行完EXECUTE时,养成好习惯,须执行DEALLOCATE PREPARE … 语句,这样可以释放执行中使用…
) while(exists(select * from sysobjects where name like '表名前缀%')) begin select @name=name from sysobjects where name like '表名前缀%' exec ('drop table '+@name) end…
MySQL数据库-条件语句.循环语句.动态执行SQL语句 1.if条件语句 delimiter \\ CREATE PROCEDURE proc_if () BEGIN ; THEN ; ELSEIF i THEN ; ELSE ; END IF; END\\ delimiter ; 2.循环语句 while循环 delimiter \\ CREATE PROCEDURE proc_while () BEGIN DECLARE num INT ; ; DO SELECT num ; ; END…