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

后端 未结 2 943
失恋的感觉
失恋的感觉 2021-01-15 21:08

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 wi

相关标签:
2条回答
  • 2021-01-15 21:45

    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.

    0 讨论(0)
  • 2021-01-15 21:45

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

    0 讨论(0)
提交回复
热议问题