MySql Stored Procedure Notes

Source: Internet
Author: User

Stored Procedures

stored procedure abbreviation procedure, procedure, is a function with no return value

To create a process:

Create procedure Procedure name ([parameter list])

Begin

Process Body

End

viewing procedures

The way the function is viewed is fully applicable to the procedure: replace the keyword with procedure

Show procedure status [like '];

View Create statement

Show CREATE PROCEDURE Pro1;

Call procedure (Procedure has no return value, select Cannot access)

The procedure has a special calling keyword: call

Call Pro1 ();

Modify Process & Delete process

Process can not be modified, can only be deleted after the new

Drop Procedure Procedure Name

Procedure parameters for process parameter problems

function parameters require data type designation, procedure is more rigorous than function

The process has its own type qualification

In: Data is only passed externally to internal use (value passing), can be a numeric value, or it can be a variable

Out: Only allow internal use of the procedure (without external data), for external use (Reference delivery: External data is emptied before it goes inside): (implied) only variables.

Inout: External can be used internally, internal modifications can also be used externally, only variables

Use syntax:

Create procedure procedure name (in Parameter name data type, out parameter name data type, inout parameter name data type)

Call: Out and inout incoming must be a variable, cannot be a numeric value

Variable must be passed in

--Setting variables

Set @int_1: = 1;

Set @int_2: = 2;

Set @int_3: = 3;

Select @int_1, @int_2, @int_3;

Call Pro1 (@int_1, @int_2, @int_3);

Select @int_1, @int_2, @int_3;

The stored procedure has a lag in the operation of the variable (return), which assigns the internal modified value to the external incoming global variable at the end of the stored procedure .

Test

Incoming data:

--Setting variables

Set @int_1: = 1;

Set @int_2: = 2;

Set @int_3: = 3;

Call Pro2 (@int_1, @int_2, @int_3);

1. Explains that local variables are independent of global variables

2. After the end of the stored procedure call, the system assigns local variables to global variables (out and inout two types only)

Writing so much, in fact, no use, the main solution to the stored procedure does not return the value of the problem. To return the internal results to external use.

MySql Stored Procedure Notes

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.