Mysql Stored Procedure example

Source: Internet
Author: User
Tags stored procedure example

Mysql Stored Procedure example (Currently I am using mysql 5.5)

This is the first time I write a mysql stored procedure, just follow the imitation of others!
Khan!

The stored procedure is as follows:

Java code
Create procedure proc_name (in parameter integer)
BEGIN
Declare variable varchar (20 );
If parameter = 1 THEN
Set variable = 'mysql ';
ELSE
Set variable = 'java ';
End if;
Insert into tb (name) values (variable );
End
Test statement:
Call proc_name (3 );

 

Java code
Create procedure abin (in parameter int)
BEGIN
If parameter = 1 THEN
Select * from tb order by id asc;
ELSE
Select * from test order by id asc;
End if;
End;
Test statement:
Call abin (2 );


Java code
Create procedure abin_1 (in parameter int)
BEGIN
Declare variable varchar (20 );
If parameter = 1 THEN
Set variable = 'windows ';
ELSE
Set variable = 'linux ';
End if;
Select parameter;
End;
Test statement:
Call abin_1 (1 );
Call abin_1 (2 );


Java code
Create procedure bing ()
BEGIN
DECLARE temp int;
Set temp = 'java ';
Update tb set name = 'abin' where id = 1;
End;

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.