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;