MySQL stored procedures

Source: Internet
Author: User

1. Simple Stored Procedure creation

Drop procedure if exists  //  CREATE definer=PROCEDURE  ' Selectorder ' ()  BEGIN    Select* from order_h; END // Call Selectorder ();

2. Stored procedure creation with parameters

Drop procedure if existsSelectorder;delimiter//  CREATE PROCEDURE' Selectorder ' (inchCustomervarchar( +))BEGIN    Select *  fromOrder_hwhereCustomerID=customer;END//Call Selectorder ('Ct9');

3. Create a stored procedure with a parameter

Drop procedure if existsSelectorder;delimiter//  CREATE PROCEDURE' Selectorder ' (out Money int)BEGIN    Select sum(Summoney) into  Money  fromOrder_hwhereCustomerID='Ct9';END//Call Selectorder (@money);SELECT @money  fromDUAL;

4. Create a stored procedure with a parameter entry

Drop procedure if existsSelectorder;delimiter//  CREATE PROCEDURE' Selectorder ' (inchCustomervarchar( +), out Money int)BEGIN    Select sum(Summoney) into  Money  fromOrder_hwhereCustomerID=customer;END//Call Selectorder ('Ct1',@money);SELECT @money  fromDUAL;

5. Stored Procedure Control statements

Drop procedure if existsSelectorder;delimiter//  CREATE PROCEDURE' Selectorder ' (inchCustomervarchar( +),inchIsmax Boolean, out Money int)BEGIN    ifIsmax Then        Select Max(Summoney) into  Money  fromOrder_hwhereCustomerID=customer; Else        Select min(Summoney) into  Money  fromOrder_hwhereCustomerID=customer; End if; /** Other syntax declaration variables DECLARE s int;        While loop while I <= n does set S = s + i;                END while;        Case if case type is 0 Then set c = ' false ';        When 1 then Set c = ' true ';        else Set c = ' Else ';    END case; */END//Call Selectorder ('Ct1', False,@money);SELECT @money  fromDUAL;

MySQL stored procedures

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.