mysql 创建存储过程
实例一:
CREATE PROCEDURE cp_test() BEGIN declare a int; declare b int; set a=1; set b=2; select a,b; END
实例二:
CREATE PROCEDURE cp_Stat_VideoData() BEGIN declare 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