MySQL Stored Procedure

Source: Internet
Author: User
1. Create the Stored Procedure drop procedure if exists sp_test;
Create procedure sp_test (
In P1 bigint,
In P2 char (64 ),
In P3 char (16)
)
Begin
-- Do somethings
End;

2. variables-define variables
Declare _ id int default 0;
-- Assign a value to the variable (Note: This method will automatically convert the data type)
Select 'id' into _ id from 'table' where 'id' = 1;
-- Assign values to variables (Note: This method does not automatically convert data types)
Set _ id = 1;
Select _ id = 1;

3. Process Control-ifelse
If 1 = 1 then
-- SQL 1;
Else
-- SQL 2
End if;

-- While
Drop procedure if exists test1;
Create procedure test1 ()
Begin
Declare I int default 1;
While I <= 100 do
Insert into rank_curr (rank_id, mbr_id, rank_val, rank_num)
Values
(1, 10000 + I,-I, I );
Set I = I + 1;
End while;
End;
Call test1;

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.