Mysql通过函数调用存储过程

use testprocedure;

##no return result
delimiter //
drop procedure if exists testselectinto//


create procedure testselectinto(id int)
begin
   declare tt int;
   set tt=0;

   select sum(total) into tt from selectinto1 b where b.id=id;
   update selectinto2 a set a.summ=tt where a.id=id;

end;
//

call testselectinto(1)//
call testselectinto(2)//
call testselectinto(1)//
call testselectinto(2)//
call testselectinto(1)//
call testselectinto(2)//
call testselectinto(1)//


##have return result

delimiter //
drop procedure if exists havereturn//

create procedure havereturn()
begin
 
end;//

通过函数调用存储过程

##function
use testprocedure
delimiter //
drop function if exists testfunction//


create function testfunction(id int)returns int
begin
 
 call testselectinto(1);
 return 1;

end ;
//

select testfunction(1);

 

函数体的使用
###

use testprocedure
delimiter //
drop function if exists testfunction//


create function testfunction(id int)returns int
begin
 
 declare tt int;
   set tt=0;

   select sum(total) into tt from selectinto1 b where b.id=id;
   update selectinto2 a set a.summ=tt where a.id=id;

 return 1;

end ;
//

select testfunction(2); 

你可能感兴趣的:(Mysql通过函数调用存储过程)