
正文
mysql 创建存储过程
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
mysql 创建存储过程
实例一:
CREATE PROCEDURE cp_test()
BEGINdeclare a int;
declare b int;set a=1;
set b=2;select a,b;END
实例二:
CREATE PROCEDURE cp_Stat_VideoData()
BEGINdeclare yestday date;
set yestday=date(date_add(NOW(), interval -1 day));
if exists(select Id from Stat_VideoHits where AddDate = yestday)
THEN
delete from Stat_VideoHits where AddDate=yestday;
end if;insert into Stat_VideoHits(Id,VideoId,Times,AddDate) select uuid(), VideoId,COUNT(1),AddDate from Coll_VideoHits
where AddDate = yestday
group by VideoId;DELETE from Sum_VideoHits;insert into Sum_VideoHits(Id,VideoId,Times,UpdateDate) select uuid(),VideoId,sum(Times),now() from Stat_VideoHits
group by VideoId;delete from Coll_VideoHits WHERE AddDate<date_add(yestday, interval -3 day);END





