How to Create a stored procedure using MYSQL Command Line

Source: Internet
Author: User

MYSQL command line is used to learn the basic knowledge in the MYSQL database process. How should I use MYSQL command line to create a stored procedure?

I tried some methods, but the first semicolon mysql thought the statement was over. For example:

 
 
  1. CREATE PROCEDURE p7 (IN b INTEGER(12))  
  2.  
  3. begin  
  4.  
  5. declare a INTEGER(12);  
  6.  
  7. set a=5;  
  8.  
  9. INSERT INTO t VALUES (a);  
  10.  
  11. SELECT s1*a FROM t WHERE b<=s1;  
  12.  
  13. End  
  14.  

If this stored procedure is directly created on the command line, an error will be reported after you enter a semicolon in the third row ...... Because MYSQL thinks this statement is over, for MYSQL

 
 
  1. CREATE PROCEDURE p7 (IN b INTEGER(12))  
  2.  
  3. begin  
  4.  
  5. declare a INTEGER(12);  
  6.  

It must be an error statement.

Then I read something and added the separator --..........

 
 
  1. DELIMITER //  
  2.  
  3. CREATE PROCEDURE p7 (IN b INTEGER(12))  
  4.  
  5. begin  
  6.  
  7. declare a INTEGER(12);  
  8.  
  9. set a=5;  
  10.  
  11. INSERT INTO t VALUES (a);  
  12.  
  13. SELECT s1*a FROM t WHERE b<=s1;  
  14.  
  15. End  
  16.  
  17. //  
  18.  

OK ............ That is to say //...... // Run as a statement between them. Therefore, MYSQL receives the complete statement for creating the stored procedure.

In-depth study on MySQL's data deletion from multiple tables

Simple MySQL large table backup method

Combination of multiple MySQL table result sets

Implementation of MySQL table sharding

MySQL authorization table usage example

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.