开发者社区> 问答> 正文

MySQL execute的使用场景举例

mysql> desc tester;
+-------+-------------+------+-----+---------+----------------+
| Field | Type        | Null | Key | Default | Extra          |
+-------+-------------+------+-----+---------+----------------+
| id    | int(10)     | NO   | PRI | NULL    | auto_increment |
| name  | varchar(20) | YES  |     | NULL    |                |
| age   | int(10)     | YES  |     | NULL    |                |
| email | varchar(20) | YES  | UNI | NULL    |                |
+-------+-------------+------+-----+---------+----------------+
4 rows in set (0.00 sec)

mysql> prepare adduser from 'insert into tester (name,age,email) values (?,?,?)';
Query OK, 0 rows affected (0.00 sec)
Statement prepared

mysql> set @name='jyd',@age=5,@email='962584902@qq.com';
Query OK, 0 rows affected (0.00 sec)

mysql> execute adduser using @name,@age,@email;
Query OK, 1 row affected (0.02 sec)

mysql> select * from tester;
+----+------+------+------------------+
| id | name | age  | email            |
+----+------+------+------------------+
|  1 | c    |   12 | c7@q.com         |
|  2 | c    |   13 | c8@q.com         |
|  3 | c    |   14 | c9@q.com         |
|  4 | c    |   15 | c10@q.com        |
|  5 | b    |   15 | c11@q.com        |
|  6 | b    |   15 | c12@q.com        |
|  7 | b    |   15 | c13@q.com        |
|  8 | b    |   15 | c14@q.com        |
|  9 | b    |   15 | c15@q.com        |
| 10 | jyd  |    5 | 962584902@qq.com |
+----+------+------+------------------+
10 rows in set (0.00 sec)

mysql> set @name='jyd11',@age=52,@email='9625811@qq.com';
Query OK, 0 rows affected (0.00 sec)

mysql> execute adduser using @name,@age,@email;
Query OK, 1 row affected (0.02 sec)

mysql> select * from tester;
+----+-------+------+------------------+
| id | name  | age  | email            |
+----+-------+------+------------------+
|  1 | c     |   12 | c7@q.com         |
|  2 | c     |   13 | c8@q.com         |
|  3 | c     |   14 | c9@q.com         |
|  4 | c     |   15 | c10@q.com        |
|  5 | b     |   15 | c11@q.com        |
|  6 | b     |   15 | c12@q.com        |
|  7 | b     |   15 | c13@q.com        |
|  8 | b     |   15 | c14@q.com        |
|  9 | b     |   15 | c15@q.com        |
| 10 | jyd   |    5 | 962584902@qq.com |
| 11 | jyd11 |   52 | 9625811@qq.com   |
+----+-------+------+------------------+
11 rows in set (0.00 sec)

展开
收起
道月芬1 2021-10-12 18:59:12 343 0
0 条回答
写回答
取消 提交回答
问答排行榜
最热
最新

相关电子书

更多
One Box: 解读事务与分析一体化数据库 HybridDB for MySQL 立即下载
One Box:解读事务与分析一体化数据库HybridDB for MySQL 立即下载
如何支撑HTAP场景-HybridDB for MySQL系统架构和技术演进 立即下载

相关镜像