Create and use a MySQL stored procedure _ MySQL

Source: Internet
Author: User
Create a MySQL stored procedure and use bitsCN.com


Create and use a MySQL stored procedure

1. create a stored procedure:

SQL code

Create procedure proc_name (out s int) -- CREATE a stored PROCEDURE. proc_name indicates that the out parameter in the stored PROCEDURE name parameter list indicates that the parameter is the return value. The input value is in s. the parameter name int indicates the parameter type.

BEGIN -- starts the stored procedure

SELECT * FROM tbl_name WHERE tbl_id = s; -- this stored procedure indicates querying the result of a tbl_id value of s in the tbl_name table

END; -- END of the stored procedure

2. call the stored procedure

SQL code

SET @ p = 0; -- SET user variables and initialize

CALL proc_name (@ p); -- CALL the CALL command of the stored procedure and put the set variables in the parameter list. note: even if the stored procedure has no variables, write (), this is consistent with the method declaration in the program.

3. View stored procedures

SQL code

SHOW PROCEDURE STATUS

4. delete a stored procedure

SQL code

Drop procedure pro_name -- Stored PROCEDURE name

BitsCN.com

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.