无法调用存储过程 错误代码 1305
Posted
技术标签:
【中文标题】无法调用存储过程 错误代码 1305【英文标题】:Cannot call Stored procedure Error code 1305 【发布时间】:2019-10-19 12:05:01 【问题描述】:数据库是关于考试安排的,这是关于在给定日期安排课程的主要存储过程。 我创建了该过程,但是当我尝试调用它时说找不到该过程。
我查看了代码但找不到语法错误,程序本身没有编译错误,(但那可能是因为我必须使用分隔符?)
DELIMITER $$
CREATE PROCEDURE schedule_course(IN in_code CHAR(3), IN in_date DATE)
BEGIN
DECLARE complete BOOLEAN DEFAULT FALSE;
DECLARE module_code CHAR(3);
DECLARE module_c CURSOR FOR
SELECT course_code FROM module WHERE course_code = in_code;
DECLARE CONTINUE HANDLER FOR NOT FOUND
SET complete = TRUE;
IF (DAYOFWEEK(in_date) = 6 OR 7) THEN
SIGNAL SQLSTATE '45000'
SET MESSAGE TEXT = 'Cannot schedule start date on a weekend'
END IF;
OPEN module_c;
mainloop : LOOP
FETCH NEXT FROM module_c INTO module_code;
IF complete THEN
SIGNAL SQLSTATE '45000'
SET MESSAGE TEXT = 'Something something'
END IF;
INSERT INTO SESSION (`code`, `date`, room)
VALUES
(module_code, in_date, NULL)
LEAVE mainloop;
END LOOP;
DELIMITER ;
CALL schedule_course(WSD, CURDATE())
错误代码:1305。PROCEDURE cameron.schedule_course 不存在
【问题讨论】:
You have an error in your SQL syntax; check the manual that corresponds to your mysql server version for the right syntax to use near 'MESSAGE TEXT = 'Cannot schedule start date on a weekend'
您的程序中有多个语法错误 - 所以它不应该编译。
【参考方案1】:
Mysql 8 显示很多错误。 我纠正了他们,逻辑是合理的,但你当然要检查它,
DELIMITER $$
CREATE DEFINER=`root`@`localhost` PROCEDURE schedule_course(IN in_code CHAR(3), IN in_date DATE)
BEGIN
DECLARE complete BOOLEAN DEFAULT FALSE;
DECLARE module_code CHAR(3);
DECLARE module_c CURSOR FOR
SELECT course_code FROM module WHERE course_code = in_code;
DECLARE CONTINUE HANDLER FOR NOT FOUND
SET complete = TRUE;
IF (DAYOFWEEK(in_date) = 6 OR DAYOFWEEK(in_date) = 7) THEN
SIGNAL SQLSTATE '45000'
SET MESSAGE_TEXT = 'Cannot schedule start date on a weekend';
END IF;
OPEN module_c;
mainloop : LOOP
FETCH NEXT FROM module_c INTO module_code;
IF complete THEN
SIGNAL SQLSTATE '45000'
SET MESSAGE_TEXT = 'Something something';
END IF;
INSERT INTO SESSION (`code`, `date`, room)
VALUES
(module_code, in_date, NULL);
LEAVE mainloop;
END LOOP;
CLOSE module_c;
END;
DELIMITER ;
【讨论】:
【参考方案2】:看来你还没有结束(END $$)
DELIMITER $$
CREATE PROCEDURE schedule_course(IN in_code CHAR(3), IN in_date DATE)
BEGIN
DECLARE complete BOOLEAN DEFAULT FALSE;
DECLARE module_code CHAR(3);
DECLARE module_c CURSOR FOR
SELECT course_code FROM module WHERE course_code = in_code;
DECLARE CONTINUE HANDLER FOR NOT FOUND
SET complete = TRUE;
IF (DAYOFWEEK(in_date) = 6 OR 7) THEN
SIGNAL SQLSTATE '45000'
SET MESSAGE TEXT = 'Cannot schedule start date on a weekend'
END IF;
OPEN module_c;
mainloop : LOOP
FETCH NEXT FROM module_c INTO module_code;
IF complete THEN
SIGNAL SQLSTATE '45000'
SET MESSAGE TEXT = 'Something something'
END IF;
INSERT INTO SESSION (`code`, `date`, room)
VALUES
(module_code, in_date, NULL)
LEAVE mainloop;
END LOOP;
END $$
DELIMITER ;
【讨论】:
以上是关于无法调用存储过程 错误代码 1305的主要内容,如果未能解决你的问题,请参考以下文章
Postgresql 11:存储过程调用错误 - 要调用过程,请使用 CALL、Java
执行存储过程 NJS-012 时出现 node-oracledb 错误
错误代码:1442。无法更新存储函数/触发器中的表“客户”,因为它已被调用此存储函数的语句使用
oracle创建存储过程时,提示错误是:错误(5,18): PL/SQL: ORA-00947: 没有足够的值?代码如下: