我正在编写我的第一个mysql过程。我有一个date
变量和两个整数变量。我将两个整数变量相乘,并将所得整数与date
变量相加。
例如:
pint=6;
noftimes=3
sdate=2020-05-05
totDays=pint*noftimes
edate=2020-05-05+totDays
我可以多个pint*noftimes
,但不能添加sdate+totDays
。而如果我加上sdate+10
,那么我得到了一个正确的增量日期值。以下是我的程序:
DELIMITER $$
CREATE DEFINER=`pattu`@`localhost` PROCEDURE `getFieldWorkDates`(IN `p_id` INT, OUT `totDays` INT, OUT `edate` DATE)
BEGIN
DECLARE noftimes int;
DECLARE pint int;
DECLARE sdate DATE;
DECLARE tdays int;
SELECT startDate into sdate from projects where idprojects=p_id;
SELECT projectDuration into noftimes from projects where idprojects=p_id;
SELECT recFreq into pint from projects where idprojects=p_id;
SET totDays=pint*noftimes;
SET edate = sdate+(pint*noftimes);
END$$
DELIMITER ;
当我执行此操作时,我收到消息,您的查询已成功执行。0行受影响
SET edate = sdate+(pint*noftimes);
您不能将整数添加到日期中。使用DATE_ADD((函数。
CREATE
DEFINER=pattu@localhost
PROCEDURE getFieldWorkDates ( IN p_id INT,
OUT totDays INT,
OUT edate DATE)
SELECT recFreq * projectDuration,
startDate + INTERVAL recFreq * projectDuration DAY
INTO totDays,
edate
FROM projects
WHERE idprojects=p_id;