mysql 函数、存储过、带循环的存储过程
时间:2014-11-27 14:39 来源:linux.it.net.cn 作者:IT
函数:
CREATE DEFINER = `root`@`localhost` FUNCTION `NewProc`(gdate datetime)
RETURNS varchar(255) CHARSET utf8
BEGIN
DECLARE x VARCHAR(255) DEFAULT '';
SET x= date_format(gdate,'%Y年%m月%d日%h时%i分%s秒');
RETURN x;
END;
存储过程:
CREATE DEFINER = `root`@`localhost` PROCEDURE `NewProc`(in parameter integer)
begin
declare variable varchar(20);
if parameter=1 then set variable='MySQL';
else set variable='PHP';
end if;
insert into t1 (id,name) values (8,variable);
end;
带循环的存储过程:
CREATE DEFINER = `root`@`localhost` PROCEDURE `NewProc`()
BEGIN
#Routine body goes here...
DECLARE i int;
set i =0 ;
l1: while i<10 DO
INSERT INTO t2 VALUES(1,'aa');
SET i=i+1;
end WHILE l1;
END;
(责任编辑:IT)
函数:
CREATE DEFINER = `root`@`localhost` FUNCTION `NewProc`(gdate datetime)
存储过程:
CREATE DEFINER = `root`@`localhost` PROCEDURE `NewProc`(in parameter integer) end;
带循环的存储过程:
CREATE DEFINER = `root`@`localhost` PROCEDURE `NewProc`() |