Home > Database > Mysql Tutorial > mysql存储过程例子_MySQL

mysql存储过程例子_MySQL

WBOY
Release: 2016-06-01 13:45:19
Original
756 people have browsed it

bitsCN.com

mysql 存储过程例子(当前我使用的是mysql 5.5)

这是我平身第一次写mysql的存储过程,不外乎先照着别人写的模仿呗!
汗!

存储过程如下:

Java代码 
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 
测试语句: 
call proc_name(3); 

 

Java代码 
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; 
测试语句: 
call abin(2); 


Java代码 
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; 
测试语句: 
call abin_1(1); 
call abin_1(2); 


Java代码 
create procedure bing() 
BEGIN 
DECLARE temp int; 
set temp='java'; 
update tb set name='abin' where id=1; 
end; 

bitsCN.com
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template