Example of the actual MySQL Stored Procedure

Source: Internet
Author: User

The following articles mainly introduce the actual operation process of the MySQL stored procedure, including the syntax description of the stored procedure and the description of related commands, if you are interested in the actual operations, you can click to read the following articles.

Stored Procedure syntax

 
 
  1. Create procedure proc_name ([IN | OUT | INOUT] param data type)
  2. BEGIN
  3. Statement
  4. END

In the MySQL command line, each statement must be separated by a semicolon (semicolon), which is the execution point of MySQL. In order to write the MySQL stored procedure, the delimiter // command is used to convert the separator //.

 
 
  1. delimiter //  

Write a simple procedure

 
 
  1. MySQL-> CREATE PROCEDURE hello()  
  2. -> BEGIN  
  3. -> SELECT "Hello World!";  
  4. -> END  
  5. -> //   
  6. Query OK, 0 rows affected (0.00 sec) 

Call the MySQL stored procedure: call proc_name

 
 
  1. MySQL-> CALL hello()//  
  2. +----------------------+  
  3. | it is a hello world. |  
  4. +----------------------+  
  5. | it is a hello world. |  
  6. +----------------------+  
  7. 1 row in set (0.00 sec)  

Delete stored procedure

 
 
  1. DROP proc_name 

Note: A stored procedure can call another MySQL stored procedure, but cannot be deleted.

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.