#用户变量 set @t = now(); SELECT DATE_FORMAT(NOW(),'%b %d %Y %h:%i %p') #使用SET初始化用户变量 SET @ab = 'abcee'; SELECT @ab := 'fghi'; SELECT @ab; #使用SELECT初始化用户变量并赋值 SELECT @var1 := '123456789'; SELECT @var1; #判断存储过程是否存在并删除; DROP PROCEDURE IF EXISTS MYpROC; CREATE PROCEDURE MyProc ( IN dMonth INT, #会话变量 IN dDay INT, #会话变量 OUT dTotalCount INT #会话变量 ) begin #声明会话变量 DECLARE MyVar int; SELECT @var1 := '9999999'; #条件查询 SELECT * from dc_log WHERE MONTH(AddTime) = dMonth AND Day(AddTime) = dDay; #通过SELECT……INTO语句赋值 SELECT COUNT(1) INTO dTotalCount from dc_log WHERE MONTH(AddTime) = dMonth AND Day(AddTime) = dDay; #通过SET语句赋值 SET MyVar = dTotalCount; #输出会话变量 SELECT MyVar; end #调用存储过程 CALL myproc(9,21,@total); #输出参数 select @total; SELECT * from dc_log;