我将日期与一些静态值进行比较,这里的一些变量是我的代码
IF v_next_date >= STR_TO_DATE('15/2/2014', '%m/%d/%Y') then
SET v_next_date = DATE_FORMAT(v_date,'%2000-%m-%d');
elseif v_next_date = v_date then
LEAVE last_update;
else
SET v_next_date = DATE_ADD(v_next_date,INTERVAL 1 MONTH);
end if;
首先,如果我想比较静态日期,然后将v_date分配给v_next_date,那么年份应为2000。 第二,我想比较2个变量 第三,如果我想将下个月的相同日期分配给v_next_date。
编辑:我的程序没有完成,我认为比较或作业存在问题
编辑:这是我的完整代码(程序):
CREATE PROCEDURE accidents.`task_7_proce`()
BEGIN
DECLARE v_finished INTEGER DEFAULT 0;
DECLARE v_pkid INTEGER;
DECLARE v_mine INTEGER;
DECLARE v_date DATETIME;
DECLARE v_lat INTEGER;
DECLARE v_lng INTEGER;
DECLARE v_next_date DATE;
DECLARE i INTEGER DEFAULT 0;
DECLARE msg varchar(100) DEFAULT 'no message';
DECLARE weather_cursor CURSOR FOR select pkid, mine_id, accident_dt, lat, lng
from test_unfilteredfull
where pkid = 46953;
DECLARE CONTINUE HANDLER
FOR NOT FOUND SET v_finished = 1;
OPEN weather_cursor;
FETCH weather_cursor INTO v_pkid, v_mine, v_date, v_lat, v_lng;
SET v_next_date = DATE_ADD(v_date,INTERVAL 1 MONTH);
last_update: loop
-- ******** update statement **************
UPDATE mytable mt INNER JOIN myvalues mv
ON mv.date = v_next_date and
mt.pkid = v_pkid
SET mt.tmax = mv.tmax, mt.tmin = mv.tmin, mt.dayl= mv.dayl ,
mt.prcp = mv.prcp , mt.srad = mv.srad, mt.swe=mv.swe, mt.vp=mv.vp
WHERE mv.Longitude_MAX >= v_lng and
mv.Longitude_MIN <= v_lng and
mv.Latitude_MAX >= v_lat and
mv.Latitude_MIN <= v_lat;
if ROW_COUNT() > 0 then
SET msg = 'Successfully updated!';
LEAVE last_update;
end if;
IF v_next_date >= STR_TO_DATE('2/15/2014', '%m/%d/%Y') then
SET v_next_date = DATE_FORMAT(v_date,'%2000-%m-%d');
elseif v_next_date = v_date then
LEAVE last_update;
else
SET v_next_date = DATE_ADD(v_next_date,INTERVAL 1 MONTH);
end if;
END LOOP last_update;
CLOSE weather_cursor;
commit;
END;