This article mainly introduces how to execute dynamic SQL statements in the MySQL stored procedure. The example analyzes the skills related to constructing and executing dynamic SQL statements in MySQL, which has some reference value, for more information about how to execute dynamic SQL statements in the MySQL stored procedure, see the following example. Share it with you for your reference. The specific implementation method is as follows:
Mysql> delimiter $ mysql> create procedure set_col_value-> (in_table VARCHAR (128),-> in_column VARCHAR (128),-> in_new_value VARCHAR (1000 ), -> in_where VARCHAR (4000)-> BEGIN-> DECLARE l_ SQL VARCHAR (4000);-> SET l_ SQL = CONCAT_ws ('',-> 'update', in_table, -> 'set', in_column, '=', in_new_value,-> 'where', in_where);-> SET @ SQL = l_ SQL;-> PREPARE s1 FROM @ SQL; -> EXECUTE s1;-> deallocate prepare s1;-> END $ Query OK, 0 rows affected (0.00 sec)
I hope this article will help you design MySQL database programs.