mysql--Stored Procedures

Source: Internet
Author: User

Stored Procedures

Definition of a stored procedure

Second, the advantages of stored procedures

Third, the use of stored procedures

3.1 Creation and invocation of stored procedures

3.2 Viewing and deletion of stored procedures

The definition of a stored procedure:

A stored procedure is a set of SQL statements that are set up to accomplish a particular function, stored in the data, and re-called without two compilations after a compilation, and can be understood as a batch statement.

Second, the advantages

① improves the reusability of code

② Simplifying operations

③ improves the security of your data

④ improves efficiency with minimal compile times and database server connection times

Third, the use of stored procedures

3.1 Creating and invoking

Create syntax:

Create procedure stored procedure name (parameter list)

Begin

Stored procedure Body (correct SQL statement)

End

Note:
1, the parameter list contains three parts
Parameter pattern parameter Name argument type
Example:
In Stuname varchar (20)

Parameter mode:
In: This parameter can be input, that is, the parameter requires the caller to pass in the value
Out: This parameter can be used as the output, that is, the parameter can be used as the return value
InOut: This parameter can be both as input and as output, that is, the parameter needs to pass in the value, but also can return the value

2. If the stored procedure body has only one sentence, begin end can omit
The end of each SQL statement in the stored procedure body must have a semicolon.
The end of the stored procedure can be reset using delimiter
Grammar:
Delimiter end tag
Case:
Delimiter $

Stored Procedure Calls

Call stored procedure name (argument list);

Case (Null argument list): Inserting 3 data into the user table


Case (with in mode parameter): Query boys name according to beauty name


Case (mode parameter with out): Determine if the user is a member

Case (mode parameter with InOut): Pass in A and b two values, eventually a and b are doubled and returned

3.2 Viewing and deletion of stored procedures

To delete a stored procedure
Syntax: drop procedure Stored Procedure name
DROP PROCEDURE chen00; the right way
DROP PROCEDURE chen00,chen02; wrong way

To view information about a stored procedure
DESC MYP2; Wrong way
SHOW CREATE PROCEDURE chen02; the right way

mysql--Stored Procedures

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.