Is there a way to execute code dynamically in MySQL, similar to “execute immediate” in Oracle?

大城市里の小女人 提交于 2019-12-01 13:27:03

It actually doesn't work like what I wrote. I just code like:

set @preparedstmt = concat('SELECT tid, LENGTH(message) len FROM ? where tid=? and first=1');
prepare stmt from prepared_stmt;
execute stmt using v_tid;
drop prepare stmt;

Just take care of the table name,it shouldn't be replaced with the placeholder.So the @preparedstmt should be generated with concat method to make a statement,which is just replaced the parameters in conditions with placeholder,but not the table name.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!