PREPARE
PREPARE
语句提供了一个服务器端预处理语句的 SQL 接口。
语法概要
- PreparedStmt
- PrepareSQL
PreparedStmt ::=
'PREPARE' Identifier 'FROM' PrepareSQL
PrepareSQL ::=
stringLit
| UserVariable
为了限制当前 TiDB 实例中的 PREPARE
语句数量,可以使用 max_prepared_stmt_count
系统变量。
示例
mysql> PREPARE mystmt FROM 'SELECT ? as num FROM DUAL';
Query OK, 0 rows affected (0.00 sec)
mysql> SET @number = 5;
Query OK, 0 rows affected (0.00 sec)
mysql> EXECUTE mystmt USING @number;
+------+
| num |
+------+
| 5 |
+------+
1 row in set (0.00 sec)
mysql> DEALLOCATE PREPARE mystmt;
Query OK, 0 rows affected (0.00 sec)
MySQL 兼容性
TiDB 中的 PREPARE
语句与 MySQL 完全兼容。如果你发现任何兼容性差异,请报告一个 bug。