BEGIN IF (SELECT work_start FROM work WHERE work_start = CONCAT(DATE_FORMAT(r_time, '%W%H:%i'))) THEN INSERT INTO reserve (New.r_id, p_id, d_id, r_time, status, null) VALUES (New.r_id, New.p_id, New.d_id, New.r_time, '已预约', null); ELSE SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = 'Data does not meet the requirements'; END IF; DECLARE count INT; SELECT COUNT(*) into count from reserve where r_time=NEW.r_time AND d_id=NEW.id; SELECT renshu into @num from work where d_id=NEW.id AND work_start = CONCAT(DATE_FORMAT(NEW.r_time, '%W%H:%i'))); IF count<=@num then update reserve set New.r_out_num=@num-count doctor_id = NEW.doctor_id AND CONCAT(DATE_FORMAT(NEW.r_time, '%W%H:%i'))); else SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = 'Appointment limit exceeded'; END IF; END有语法错误
时间: 2024-03-28 15:38:09 浏览: 135
根据你提供的代码,发现有一些语法错误。首先,第一个 IF 语句中的 SELECT 语句缺少 FROM 子句,应该指定查询的表名。其次,在第一个 IF 语句中的 INSERT INTO 语句中,VALUES 子句中缺少一列的值,应该指定 r_out_num 的值。最后,第二个 SELECT 语句中的 doctor_id 和 CONCAT 函数之间应该用逗号分隔,而不是 AND。下面是修正后的代码:
BEGIN
IF (SELECT work_start FROM work WHERE work_start = CONCAT(DATE_FORMAT(r_time, '%W%H:%i')) FROM work) THEN
INSERT INTO reserve (New.r_id, p_id, d_id, r_time, status, r_out_num) VALUES (New.r_id, New.p_id, New.d_id, New.r_time, '已预约', null);
ELSE
SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = 'Data does not meet the requirements';
END IF;
DECLARE count INT;
SELECT COUNT(*) INTO count FROM reserve WHERE r_time=NEW.r_time AND d_id=NEW.id;
SELECT renshu INTO @num FROM work WHERE d_id=NEW.id AND work_start = CONCAT(DATE_FORMAT(NEW.r_time, '%W%H:%i'));
IF count <= @num THEN
UPDATE reserve SET r_out_num=@num-count, doctor_id=NEW.doctor_id, r_time=CONCAT(DATE_FORMAT(NEW.r_time, '%W%H:%i'));
ELSE
SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = 'Appointment limit exceeded';
END IF;
END
阅读全文