mysql 函数 存储过程

函数

CREATE DEFINER=`root`@`localhost` FUNCTION `functio`(a int ,b int) RETURNS int(11)
return a+b

//两个方式

create FUNCTION functio2(a int ,b int) returns int
begin
return a*b;
end

存储过程

CREATE PROCEDURE simple(in a int ,in b int,out c INT)
BEGIN
set c:=a+b;
end

CALL simple(1,2,@c);

select @c;

//concat 连接

CREATE  PROCEDURE siinsert( in num int )
BEGIN
declare i int default 0;
-- START TRANSACTION;
while i<num do
insert into person1 (nane, age) values (concat('TOM',i),i);
set i=i+1;
end while;
-- COMMIT;
end

猜你喜欢

转载自www.cnblogs.com/simly/p/11654195.html