PREPARE

The PREPARE statement provides an SQL interface to server-side prepared statements.

Synopsis

PreparedStmt

PREPARE - 图1

PrepareSQL

PREPARE - 图2

  1. PreparedStmt ::=
  2. 'PREPARE' Identifier 'FROM' PrepareSQL
  3. PrepareSQL ::=
  4. stringLit
  5. | UserVariable

PREPARE - 图3

Note

For each PREPARE statement, the maximum number of placeholders is 65535.

To limit the number of PREPARE statements in the current TiDB instance, you can use the max_prepared_stmt_count system variable.

Examples

  1. mysql> PREPARE mystmt FROM 'SELECT ? as num FROM DUAL';
  2. Query OK, 0 rows affected (0.00 sec)
  3. mysql> SET @number = 5;
  4. Query OK, 0 rows affected (0.00 sec)
  5. mysql> EXECUTE mystmt USING @number;
  6. +------+
  7. | num |
  8. +------+
  9. | 5 |
  10. +------+
  11. 1 row in set (0.00 sec)
  12. mysql> DEALLOCATE PREPARE mystmt;
  13. Query OK, 0 rows affected (0.00 sec)

MySQL compatibility

The PREPARE statement in TiDB is fully compatible with MySQL. If you find any compatibility differences, report a bug.

See also