MySQL Create a detailed example tutorial for stored procedures (1/9)

Source: Internet
Author: User
Tags mysql create mysql tutorial

MySQL tutorial Creating stored Procedures
"Pr_add" is a simple MySQL stored procedure that has two input parameters of type int, "A", "B", and returns the and of the two parameters.

drop procedure if exists pr_add;

--Calculate the sum of two numbers

CREATE PROCEDURE Pr_add
(
a int,
b int
)
Begin
declare c int;

If A is null then
Set a = 0;
End If;

If B is null then
Set B = 0;
End If;

Set C = a B;

Select C as Sum;

/*
return C; --cannot be used in a MySQL stored procedure. Return can only appear in the function.
*/
End
Second, call the MySQL stored procedure
Call Pr_add (10, 20);
Execute the MySQL stored procedure, the stored procedure parameter is the MySQL user variable.

Set @a = 10;
Set @b = 20;

Home 1 2 3 4 5 6 7 8 9 last
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.