Here is the real starting point. First, let's look at the data in the table */
Mysql tutorial> select count (*) from cdb_invites;
+ ---------- +
| Count (*) |
+ ---------- +
| 1, 261 |
+ ---------- +
1 row in set (0.00 sec)Copy
CodePS tutorial, the following sections should note:
First sentence: delimiter // This is used
MysqlClient-side delimiter command to change the statement delimiters from; //
The name of a stored procedure is hi. No parameter required
The center is to declare local variables and insert them cyclically.
Last sentence: end // This is the real end.
Then, from now on, unless you log on to mysql again. Otherwise, the current commands are all ended.
- /* Create a stored procedure to insert several data entries to a table cyclically */
- Mysql> delimiter //
- Mysql> create procedure hi ()
- -> Begin
- -> Declare a int (10 );
- -> Set a = 1;
- -& Gt; while a & lt; 100 do
- -> Insert into cdb_invites values (1280480286, '10. 0.7.7 ', a, 1 );
- -> Set a = a + 1;
- -> End while;
- -> End //
- Query OK, 0 rows affected (0.00 sec)
- /* Call the stored procedure once. Check the table and add 99 new data records */
- Mysql> call hi ()//
- Query OK, 1 row affected (0.01 sec)
-
- Mysql> select count (*) from cdb_invites //
- + ---------- +
- | Count (*) |
- + ---------- +
- | 1, 360 |
- + ---------- +
- 1 row in set (0.00 sec)