Mysql Stored Procedure syntax

Source: Internet
Author: User
Tags mysql tutorial

Mysql tutorial Stored Procedure syntax

Variable definition:

Declare variable_name [, variable_name...] datatype [default value];


Datatype is the data type of mysql, such as int, float, date, varchar (length)

Example:

Declare l_int int unsigned default 4000000; declare l_numeric numeric (9.95) default 1999; declare l_date default '2017-12-31 '; declare l_datetime default '2017-12-31 23:59:59 '; declare l_varchar varchar (255) default 'this will not be padded ';

Variable assignment

Set variable name = expression value [, variable_name = expression...]
 

Parameters

Mysql stored procedure parameters are used in the definition of stored procedures. There are three parameter types: in, out, And inout.

Create procedure | function ([[in | out | inout] Parameter Name Data class...])

 

In input parameters

Indicates that the value of this parameter must be specified when the stored procedure is called. Modifying the value of this parameter in the stored procedure cannot be returned, which is the default value.

Out output parameters

This value can be changed within the stored procedure and can be returned

Inout Input and Output Parameters

Can be changed and returned.

 


Stored Procedure:

 

Syntax:

Create procedure p ()

Begin

/* Body of the stored procedure */

End
Create procedure productpricing ()

Begin

Select avg (pro_price) as priceaverage

From products;

End;

# Begin... End is the subject definition of the stored procedure.

# The mysql Delimiter is a semicolon (;)

The method to call a stored procedure is:

 

# Add the process name and brackets to the call.

# For example, call the stored procedure defined above

Call productpricing ();

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.