4. mysql stored procedure

Source: Internet
Author: User

C:\Program Files\mysql\mysql Server 5.1\bin

1.1 Defining a stored procedure with no parameters
Define statement End with//
Delimiter//
CREATE PROCEDURE Proc_teacher_noparam ()
Begin
SELECT * from teacher;
End
//

Define statement end use;
delimiter;

1.2. Calling a stored procedure with no parameters
Call Proc_teacher_noparam ();


2.1 Stored procedures that define input parameters
Define statement End with//
Delimiter//
CREATE PROCEDURE Proc_teacher_inparam (in n int)
Begin
SELECT * from teacher where id=n;
End
//
Define statement end use;
delimiter;

2.2. Stored procedures that invoke input parameters
Defining variables
Set @n=1;

Call a stored procedure
Call Proc_teacher_inparam (@n);


3.1 Defining a stored procedure with output parameters
drop procedure if exists proc_teacher_outparam;
Delimiter//
CREATE PROCEDURE Proc_teacher_outparam (out n int)
Begin
Select COUNT (*) into n from teacher;
End
//
delimiter;

3.2 Stored procedures that call output parameters
Set @n=1;
Call Proc_teacher_outparam (@n);
Select @n;

4. Define stored procedures with input and output parameters
Delimiter//
drop procedure if exists proc_teacher_in_outparam;
CREATE PROCEDURE Proc_teacher_in_outparam (in n int,out o int)
Begin
Select COUNT (*) into O from teacher where id=n;
End
//
delimiter;

4.2 Calling a stored procedure with input and output parameters
Sex @n=1;
Call Proc_teacher_inoutparam (1,@n);
Select @n;

5.1 Creating an input-output parameter is a stored procedure of the same variable
Delimiter//
drop procedure if exists proc_teacher_inoutparam;
CREATE PROCEDURE Proc_teacher_inoutparam (inout n int)
Begin
Select COUNT (*) into N from teacher where id=n;
End
//

delimiter;

5.2 Calling the input-output parameter is a stored procedure of the same variable
Sex @n=1;
Call Proc_teacher_inoutparam (@n);
Select @n;












4. mysql stored procedure

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.