MYSQL动态查询拼接的表名的SQL脚本实现(MYSQL动态执行SQL脚本)

可以使用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 … 语句,这样可以释放执行中使用的所有数据库资源(如游标)。不仅如此,如果一个session的预处理语句过多,可能会达到max_prepared_stmt_count的上限值。

跟MYSQL类似:使用完毕需要关闭PrepareStament 。参见:https://dev.mysql.com/doc/refman/8.0/en/deallocate-prepare.html

猜你喜欢

转载自www.cnblogs.com/leodaxin/p/10340651.html
今日推荐