MySQL 5.0 stored Procedure Learning

Source: Internet
Author: User

I. Creating a stored Procedure

1. Basic grammar:

CREATE PROCEDURE Sp_name ()

Begin

.........

End

2. Parameter transfer

Two. Call the stored procedure

1. Basic syntax: Call Sp_name ()

Note: The stored procedure name must be followed by parentheses, even if the stored procedure has no parameter passing

Three. Delete stored procedures

1. Basic grammar:

drop procedure sp_name//

2. Matters needing attention

(1) cannot delete another stored procedure in one stored procedure, can only call another stored procedure

Four. blocks, conditions, loops

1. Block definition, commonly used

Begin

......

End

You can also alias a block, such as:

Lable:begin

...........

End lable;

You can use leave lable to jump out of blocks and execute code after blocks

2. Conditional statement

The following are the referenced contents:
If condition Then
Statement
Else
Statement
End If;

3. Circular statements

(1). While loop

The following are the referenced contents:
[Label:] While expression do
Statements
End while [Label];

(2). Loop loop

The following are the referenced contents:
[Label:] LOOP
Statements
End LOOP [Label];

(3). Repeat until cycle

The following are the referenced contents:
[Label:] REPEAT
Statements
UNTIL expression
End REPEAT [Label];

Five. Other common commands

1.show Procedure Status

Displays basic information about stored procedures stored in the database, including the owning database, stored procedure name, creation time, and so on

2.show CREATE PROCEDURE Sp_name

Show details of a stored procedure

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.