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