我无法将存储过程从Firebird转换为MySQL。
这是我现有的Firebird代码:
CREATE OR ALTER PROCEDURE GET_EOMONTH (
selectmonth integer,
selectyear integer)
returns (
lastdate timestamp)
as
declare variable vmonth integer;
declare variable vyear integer;
begin
VMONTH = selectmonth+1;
VYEAR = selectyear;
if (VMONTH=13) then
BEGIN
vmonth = 1;
vyear = selectyear + 1;
END
LASTDATE = CAST(VMONTH || '/1/' || VYEAR AS DATE) - 1;
/* Procedure Text */
suspend;
end^
然后我将上面的代码修改为:
CREATE PROCEDURE GET_EOMONTH (
selectmonth integer,
selectyear integer)
returns (
lastdate timestamp)
as
declare variable vmonth integer;
declare variable vyear integer;
begin
VMONTH = selectmonth+1;
VYEAR = selectyear;
if (VMONTH=13) then
BEGIN
vmonth = 1;
vyear = selectyear + 1;
END
LASTDATE = CAST(VMONTH || '/1/' || VYEAR AS DATE) - 1;
/* Procedure Text */
suspend;
end
从上面的代码我得到以下错误:
您的SQL语法有错误;检查手册 对应于您的MySQL服务器版本,以便使用正确的语法 靠近'( lastdate timestamp)as declare variable vmonth integer'在第4行* /
- 编辑
我再次修改了这个:
DELIMITER $$
CREATE PROCEDURE GET_EOMONTH (
IN selectmonth INT,
IN selectyear INT,
OUT LASTDATE VARCHAR(100))
BEGIN
DECLARE VMONTH INT;
DECLARE VYEAR INT;
SET VMONTH = selectmonth+1;
SET VYEAR = selectyear;
IF (VMONTH=13) THEN
BEGIN
SET VMONTH = 1;
SET VYEAR = selectyear + 1;
END;
END IF;
SET LASTDATE = CAST(VMONTH || '/1/' || VYEAR AS DATE) - 1;
SELECT @LASTDATE;
END
END$$
但是,错误说:
SQL错误(1064):您的SQL语法中有错误;检查 手册,对应右边的MySQL服务器版本 要在' END'附近使用的语法在第19行
请建议。
- 编辑
现在我修改这样的代码:
DELIMITER $$
CREATE PROCEDURE GET_EOMONTH (
IN selectmonth INT,
IN selectyear INT,
OUT LASTDATE VARCHAR(100))
BEGIN
DECLARE VMONTH INT;
DECLARE VYEAR INT;
SET VMONTH = selectmonth+1;
SET VYEAR = selectyear;
IF (VMONTH=13) THEN
BEGIN
SET VMONTH = 1;
SET VYEAR = selectyear + 1;
END;
END IF;
SET LASTDATE = str_to_date(CONCAT(VYEAR, "-", VMONTH, "-1"), '%y/%m/%d') -1;
SELECT @LASTDATE;
END$$
DELIMITER ;
它有效。