Beckham _ mysql stored procedure, Beckham _ mysql

Source: Internet
Author: User

Beckham _ mysql stored procedure, Beckham _ mysql
Stored ProcedureBrief:
1. What is a stored procedure?
2. Use stored procedures

 

I. Stored Procedure

Similar to a function, a piece of code is encapsulated. You can call this stored procedure to execute this code. In the encapsulated statement body, you can use control statements such as if/else, case, and while to program SQL statements.


Ii. Use stored procedures

2.1 view existing stored procedures



2.2 create a stored procedure

A. Stored Procedure without Parameters

Delimiter //

Create procedure p1 ()

Begin

Select count (*) from goods;

End //

Call the Stored Procedure p1 ()



B. Stored Procedures with parameters (parameters are used to save running results)

 

Delimiter //

Create procedure p2 (out a int)

Begin

Select count (*) into a from goods;

End //

Delimiter;

 


Call Stored Procedure p2


(Note: Define variable a to maintain the p2 result of the stored procedure, and then display the value of variable)

C. Stored Procedures with parameters (parameters are used for running)

Delimiter //

Create procedure p3 (in a int)

Begin

Select goods_id, goods_name, shop_price from goods where goods_id =;

End //

Delimiter;

 

 

 

 

 

 


Call Stored Procedure p3

D. Stored Procedure with if/else

Call

E. Stored Procedure with while

 

2.3 Delete A Stored Procedure

Summary: differences between stored procedures and functions in mysql

A. Different Names

B. The stored procedure does not return values.


The quieter you become, the more you are able to hear!

Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.

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.