存储过程

show procedure status
show create procedure proc_name;

delimiter //
create procedure p()
begin
select * from sign_event;
end//
delimiter ;


delimiter //
create procedure p2(n int)
begin
select * from sign_event where id=n;
end//
delimiter ;

call p2(2)


delimiter //
create procedure in_name(in name varchar(20),in pwd varchar(20))
begin
insert into proc_test(username,password) values (name,pwd);
end //
delimiter ;

delimiter //
create procedure in_info(in name varchar(20),in pwd varchar(20),in age int(10),in salary float(10,2),in work_years int(10),in level int(10))
begin
insert into proc_test(username,password,age,salary,work_years,level) values(name,pwd,age,salary,work_years,level);
end//
delimiter ;








delimiter //
create procedure p3(str chr(1))
begin
if str='h' then
select * from sign_event where id>2;
else
select * from sign_event where id<7;
end if;
end //
delimiter ;

delimiter //
create procedure p3(str char(1))
begin
if str='h' then
select username from proc_test where id>2;
else
select username from proc_test where id<7;
end if;
end //
delimiter ;

call p3('g')

'''
工资大于5000,输出工作年限
工资小于5000,输出姓名
'''
delimiter $$
create procedure p4(n float)
begin
if n>5000 then
select username,work_years from proc_test where level<3;
else
select username,work_years from proc_test where level>3;
end if;
end $$
delimiter ;



\d $$
create function  get_name1(x int)
returns varchar(20)
begin
	return (select username from proc_test where id=x);
end $$
\d ;

select * from proc_test where username=get_name(2);


工作年限>y,等级>l人数
delimiter //
create procedure count_num(in y int(10),in l int(10),out c int)
begin
select count(*) into c from proc_test where work_years>y and level>l;
end //
delimiter ;

call count_num(3,4,@num);
select @num;


delimiter //
create procedure count_num1(in s float(10,2),in l int(10),out c int)
begin
select count(*) into c from proc_test where salary>s and leveln1 then
set n = n-n1;
else
set n = n+n1;
end if;
end //
delimiter ;
















call in_name('jack','abc123')

你可能感兴趣的:(笔记)