Simple Mysql Stored Procedure tutorial

Source: Internet
Author: User
Tags mysql stored procedure tutorial

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.

    1. /* Create a stored procedure to insert several data entries to a table cyclically */
    2. Mysql> delimiter //
    3. Mysql> create procedure hi ()
    4. -> Begin
    5. -> Declare a int (10 );
    6. -> Set a = 1;
    7. -& Gt; while a & lt; 100 do
    8. -> Insert into cdb_invites values (1280480286, '10. 0.7.7 ', a, 1 );
    9. -> Set a = a + 1;
    10. -> End while;
    11. -> End //
    12. Query OK, 0 rows affected (0.00 sec)
    1. /* Call the stored procedure once. Check the table and add 99 new data records */
    2. Mysql> call hi ()//
    3. Query OK, 1 row affected (0.01 sec)
    4.  
    5. Mysql> select count (*) from cdb_invites //
    6. + ---------- +
    7. | Count (*) |
    8. + ---------- +
    9. | 1, 360 |
    10. + ---------- +
    11. 1 row in set (0.00 sec)

    Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.