mysql> PREPARE prod FROM "INSERT INTO examlple VALUES(?,?)"; mysql> SET @p='1'; mysql> SET @q='2'; mysql> EXECUTE prod USING @p,@q; mysql> SET @name='3'; mysql> EXECUTE prod USING @p,@name; mysql> DEALLOCATE PREPARE prod;
例如: mysql> prepare optimize_tables from "optimize table temp"; Query OK, 0 rows affected (0.00 sec) Statement prepared mysql> execute optimize_tables; +-----------+----------+----------+----------+ | Table | Op | Msg_type | Msg_text | +-----------+----------+----------+----------+ | test.temp | optimize | status | OK | +-----------+----------+----------+----------+ 1 row in set (0.37 sec) mysql> deallocate prepare optimize_tables; Query OK, 0 rows affected (0.00 sec) -------------------------------------------------------------------------- mysql> prepare md5sum from 'select md5(?) AS md5sum'; Query OK, 0 rows affected (0.00 sec) Statement prepared mysql> set @a=111; Query OK, 0 rows affected (0.00 sec) mysql> set @b=222; Query OK, 0 rows affected (0.00 sec) mysql> execute md5sum using @a; +----------------------------------+ | md5sum | +----------------------------------+ | 698d51a19d8a121ce581499d7b701668 | +----------------------------------+ 1 row in set (0.00 sec) mysql> execute md5sum using @b; +----------------------------------+ | md5sum | +----------------------------------+ | bcbe3365e6ac95ea2c0343a2395834dd | +----------------------------------+ 1 row in set (0.00 sec) mysql> drop prepare md5sum; Query OK, 0 rows affected (0.00 sec) --------------------------------------------------------------------------------------