MySQL CREATE a stored procedure detailed instance tutorial (1/9)

Source: Internet
Author: User
Tags mysql create mysql tutorial

Create a stored procedure in the mysql tutorial
"Pr_add" is a simple mysql stored procedure, which has two int-type input parameters: "a" and "B", and returns the sum 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 mysql stored procedures. Return can only appear in functions.
*/
End;
Ii. Call the mysql Stored Procedure
Call pr_add (10, 20 );
Execute the mysql stored procedure. The stored procedure parameter is a mysql user variable.

Set @ a = 10;
Set @ B = 20; 1 2 3 4 5 6 7 8 9

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.