我无法将存储过程从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服务器版本对应的手册,以获得正确的语法,将near'(lastdate timestamp)用作第4行的declare variable vmonth integer'*/
--编辑
我又修改了一下:
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服务器版本相对应的手册,以获得第19行“end”附近使用的正确语法
请给我建议。
--编辑
现在我修改代码如下:
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 ;
而且很有效。
暂无答案!
目前还没有任何答案,快来回答吧!