Stored procedures for MySQL database (i)

Source: Internet
Author: User

Stored procedures for MySQL database
Conventional
Create routine
Alter
Execute
Security
Definer

The default is to select the appropriate database when creating the stored procedure (use db_name)
Therefore, you cannot write this statement in a stored procedure while writing a stored procedure

Delimiter Client

Using the delimiter client to set the Terminator
Delimiter//
Primarily to avoid terminator conflicts with SQL statements in stored procedures

Create a program or a function
CREATE PROCEDURE | function

Learning Stored Procedures
First of all, we should learn the basics of several operations
Create, invoke, modify, delete
So, let's take a few examples to deepen the impression.

Delete a stored procedure

Drop procedure | function if exists //


View a stored procedure

Create Procedure | function db_name //


View details of a stored procedure

procedure | function  like ' Proname ' //

Use case one, write a stored procedure that has a simple query function

When using the delimiter client, it will be processed in the form of//.
Then be sure to call the same form when you create and invoke the stored procedure.
Either always use it, or always use//

1. Create a stored procedure

// Create procedure int )beginSelectcount(* into from member; End //

2. Call the stored procedure

// Call Simplepro (@a//Select@a//

When calling a stored procedure, specify an alias for the output to invoke.
Where A is just an alias of the specified


Use case two, write a simple storage function
1. Create a storage function

// Create function Char (returnschar()return concat (' Hello, '" ! ' )//

2. Call storage function

// Select Hello ('world! ' //

Stored procedures for MySQL database (i)

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.