Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/66.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mysql程序,不支持任何年份_Mysql_Stored Procedures - Fatal编程技术网

Mysql程序,不支持任何年份

Mysql程序,不支持任何年份,mysql,stored-procedures,Mysql,Stored Procedures,我正在使用一个MySQL过程根据两个不同的表获取商店的开门和关门时间。正常的“营业时间”定义为营业/关门时间和列周天数(1-7)。为了定制正常的开门/关门时间,我还有一个名为“shop\u hours\u special”的表,它是用一个day of year列定义的 如果我运行参数calltimesdate('2013-01-02','1','false')即使商店在这个日期营业,我也会得到空结果 如果任何MySQL的策划者能给我一些建议,告诉我如何让它在当前以外的年份工作,我将不胜感激 DE

我正在使用一个MySQL过程根据两个不同的表获取商店的开门和关门时间。正常的“营业时间”定义为营业/关门时间和列周天数(1-7)。为了定制正常的开门/关门时间,我还有一个名为“shop\u hours\u special”的表,它是用一个day of year列定义的

如果我运行参数
calltimesdate('2013-01-02','1','false')
即使商店在这个日期营业,我也会得到空结果

如果任何MySQL的策划者能给我一些建议,告诉我如何让它在当前以外的年份工作,我将不胜感激

DELIMITER $$
DROP PROCEDURE IF EXISTS timesDate$$

CREATE PROCEDURE timesDate(IN searchedDate DATE, IN dType TINYINT(3), IN ignoreCurrentTime BOOLEAN)
BEGIN
    DECLARE final_o_time, final_c_time, o_time, c_time, curTime TIME;  
    DECLARE dayYear, dayWeek, curDay INT;
    DECLARE special_exist BOOLEAN;

    SET dayYear = DAYOFYEAR(searchedDate);
    SET dayWeek = WEEKDAY(searchedDate) + 1;
    SET curDay = DAYOFYEAR(NOW());
    SET curTime = TIME(NOW());

    SELECT IF(COUNT(*) > 0, TRUE, FALSE), open_time, close_time INTO special_exist, o_time, c_time
        FROM shop_hours_special
        WHERE day_of_year = dayYear AND `type` = dType;

    IF special_exist THEN
        IF IgnoreCurrentTime THEN
            SET final_o_time = o_time;
            SET final_c_time = c_time;
        ELSEIF dayYear < curDay THEN
            SET final_o_time = NULL;
            SET final_c_time = NULL;
        ELSEIF dayYear = curDay THEN
            IF curTime < o_time THEN
                SET final_o_time = o_time;
                SET final_c_time = c_time;
            ELSEIF curTime < c_time THEN
                SET final_o_time = curTime;
                SET final_c_time = c_time;
            ELSE
                SET final_o_time = NULL;
                SET final_c_time = NULL;
            END IF;
        ELSE
            SET final_o_time = o_time;
            SET final_c_time = c_time;
        END IF;
    ELSE
        SELECT open_time, close_time INTO o_time, c_time
        FROM shop_hours
        WHERE day_of_week = dayWeek AND (open_time != MAKETIME(0,0,0) OR close_time != MAKETIME(0,0,0)) AND `type` = dType;

        IF IgnoreCurrentTime THEN
            SET final_o_time = o_time;
            SET final_c_time = c_time;
        ELSEIF dayYear < curDay THEN
            SET final_o_time = NULL;
            SET final_c_time = NULL;
        ELSEIF dayYear = curDay THEN
            IF curTime < o_time THEN
                SET final_o_time = o_time;
                SET final_c_time = c_time;
            ELSEIF curTime < c_time THEN
                SET final_o_time = curTime;
                SET final_c_time = c_time;
            ELSE
                SET final_o_time = NULL;
                SET final_c_time = NULL;
            END IF;
        ELSE
            SET final_o_time = o_time;
            SET final_c_time = c_time;
        END IF;

    END IF;

    SELECT final_o_time, final_c_time;

END$$
DELIMITER ;

为什么不使用连接?你需要使用存储过程吗?@charliexx正如波希米亚人所说,有了
join
date
功能,你就可以找到一个漂亮的解决方案。是什么让你有了一个sp?我无法完成一个工作连接,所以我入侵了一个过程。。
CREATE TABLE `shop_hours` (
  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `shop_id` int(11) unsigned NOT NULL,
  `type` tinyint(3) NOT NULL DEFAULT '1',
  `day_of_week` int(11) NOT NULL,
  `open_time` time NOT NULL,
  `close_time` time NOT NULL,
  PRIMARY KEY (`id`),
  KEY `shop_id` (`shop_id`),
  CONSTRAINT `shop_hours_ibfk_1` FOREIGN KEY (`shop_id`) REFERENCES `shops` (`id`) ON DELETE CASCADE ON UPDATE NO ACTION
) ENGINE=InnoDB DEFAULT CHARSET=utf8;


INSERT INTO `shop_hours` (`id`, `shop_id`, `type`, `day_of_week`, `open_time`, `close_time`)
VALUES
    (1,1,1,1,'09:30:00','20:00:00'),
    (2,1,1,2,'09:30:00','20:00:00'),
    (3,1,1,3,'09:30:00','20:00:00'),
    (4,1,1,4,'09:30:00','20:00:00'),
    (5,1,1,5,'09:30:00','20:00:00'),
    (6,1,1,6,'11:00:00','20:00:00'),
    (7,1,1,7,'11:00:00','20:00:00'),
    (8,1,2,1,'11:45:00','12:30:00'),
    (9,1,2,2,'11:45:00','12:30:00'),
    (10,1,2,3,'11:45:00','12:30:00'),
    (11,1,2,4,'11:45:00','12:30:00'),
    (12,1,2,5,'11:45:00','12:30:00'),
    (13,1,2,6,'00:00:00','00:00:00'),
    (14,1,2,7,'00:00:00','00:00:00');

CREATE TABLE `shop_hours_special` (
  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `shop_id` int(11) unsigned NOT NULL,
  `type` tinyint(3) NOT NULL DEFAULT '1',
  `day_of_year` int(11) NOT NULL,
  `open_time` time NOT NULL,
  `close_time` time NOT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `unique` (`shop_id`,`type`,`day_of_year`),
  KEY `shop_id` (`shop_id`),
  CONSTRAINT `shop_hours_special_ibfk_1` FOREIGN KEY (`shop_id`) REFERENCES `shops` (`id`) ON DELETE CASCADE ON UPDATE NO ACTION
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

INSERT INTO `shop_hours_special` (`id`, `shop_id`, `type`, `day_of_year`, `open_time`, `close_time`)
VALUES
    (1,1,1,1,'00:00:00','00:00:00'),
    (2,1,1,92,'00:00:00','00:00:00'),
    (3,1,1,96,'00:00:00','00:00:00'),
    (4,1,1,97,'00:00:00','00:00:00'),
    (5,1,1,99,'00:00:00','00:00:00'),
    (6,1,1,100,'00:00:00','00:00:00'),
    (7,1,1,125,'00:00:00','00:00:00'),
    (8,1,1,138,'00:00:00','00:00:00'),
    (9,1,1,148,'00:00:00','00:00:00'),
    (10,1,1,149,'00:00:00','00:00:00'),
    (11,1,2,1,'00:00:00','00:00:00'),
    (12,1,2,92,'00:00:00','00:00:00'),
    (13,1,2,96,'00:00:00','00:00:00'),
    (14,1,2,97,'00:00:00','00:00:00'),
    (15,1,2,99,'00:00:00','00:00:00'),
    (16,1,2,100,'00:00:00','00:00:00'),
    (17,1,2,125,'00:00:00','00:00:00'),
    (18,1,2,138,'00:00:00','00:00:00'),
    (19,1,2,148,'00:00:00','00:00:00'),
    (20,1,2,149,'00:00:00','00:00:00'),
    (21,1,1,358,'11:00:00','15:00:00'),
    (22,1,2,358,'00:00:00','00:00:00'),
    (23,1,1,359,'00:00:00','00:00:00'),
    (24,1,2,359,'00:00:00','00:00:00'),
    (25,1,1,360,'00:00:00','00:00:00'),
    (26,1,2,360,'00:00:00','00:00:00'),
    (27,1,2,361,'00:00:00','00:00:00'),
    (28,1,1,361,'00:00:00','00:00:00'),
    (29,1,1,366,'11:00:00','14:00:00'),
    (30,1,2,366,'00:00:00','00:00:00'),
    (31,1,2,362,'00:00:00','00:00:00'),
    (32,1,2,363,'00:00:00','00:00:00');