title: PREPARE summary: TiDB 数据库中 PREPARE 的使用概况。

PREPARE

PREPARE 语句为服务器端预处理语句提供 SQL 接口。

语法图

PreparedStmt:

PreparedStmt

PrepareSQL:

PrepareSQL

示例

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

MySQL 兼容性

PREPARE 语句与 MySQL 完全兼容。如发现任何兼容性差异,请在 GitHub 上提交 issue

另请参阅