开发者

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

Like EXECUTE IMMEDIATE in Oracle, is there any way to execute code dynamically in a MySQL stored procedure开发者_高级运维?

I really want to use a prepared statement within a MySQL stored procedure, to generate a new SQL statement in each iteration of a loop.


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.


MariaDB is supporting EXECUTE IMMEDIATE ince 10.2 KB doc is : https://mariadb.com/kb/en/execute-immediate/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜