只会写sql server的存储过程
今天试着写了个sql存储过程,却一直报错,求大神们帮忙看看
在线等
以下截取部分代码DELETE FROM shipmentQueryResultTable;
DECLARE table_index int,table_name VARCHAR(50),stmt VARCHAR(2000);
IF uin = 0
THEN
END IF
ELSE
THEN
table_index = uin % 16;
IF table_type = 1
THEN
SET table_name = CONCAT('expresssucshipmenttable', CAST(table_index AS VARCHAR(4)));
END
ELSEIF table_type = 2
THEN
SET table_name = CONCAT('expresstimeoutshipmenttable',CAST(table_index AS VARCHAR(4)));
END
IF shipmentID = 0
THEN
SET @sqlstr = comcat('INSERT INTO shipmentQueryResultTable SELECT * FROM ',table_name ,
'WHERE shipmentTime between ', fromDateTime, " and ", toDateTime);
END
ELSE
THEN
SET @sqlstr = comcat('INSERT INTO shipmentQueryResultTable SELECT * FROM ',table_name ,
'WHERE (shipmentTime between ', fromDateTime, " and ", toDateTime, ")AND shipmentID=", shipmentID);
END
prepare stmt from @sqlstr;
execute stmt;
END
END
今天试着写了个sql存储过程,却一直报错,求大神们帮忙看看
在线等
以下截取部分代码DELETE FROM shipmentQueryResultTable;
DECLARE table_index int,table_name VARCHAR(50),stmt VARCHAR(2000);
IF uin = 0
THEN
END IF
ELSE
THEN
table_index = uin % 16;
IF table_type = 1
THEN
SET table_name = CONCAT('expresssucshipmenttable', CAST(table_index AS VARCHAR(4)));
END
ELSEIF table_type = 2
THEN
SET table_name = CONCAT('expresstimeoutshipmenttable',CAST(table_index AS VARCHAR(4)));
END
IF shipmentID = 0
THEN
SET @sqlstr = comcat('INSERT INTO shipmentQueryResultTable SELECT * FROM ',table_name ,
'WHERE shipmentTime between ', fromDateTime, " and ", toDateTime);
END
ELSE
THEN
SET @sqlstr = comcat('INSERT INTO shipmentQueryResultTable SELECT * FROM ',table_name ,
'WHERE (shipmentTime between ', fromDateTime, " and ", toDateTime, ")AND shipmentID=", shipmentID);
END
prepare stmt from @sqlstr;
execute stmt;
END
END
table_type int
uin bigint
shipmentID bigint
fromDateTime datetime
toDateTime datetime
DELETE FROM shipmentQueryResultTable;
DECLARE table_index int,table_name VARCHAR(50),stmt VARCHAR(2000);IF uin = 0
THEN
IF shipmentID = 0
THEN
IF table_type = 1
THEN
INSERT INTO shipmentQueryResultTable SELECT * FROM expresssucshipmenttable0 WHERE shipmentTime BETWEEN fromDateTime AND toDateTime;
INSERT INTO shipmentQueryResultTable SELECT * FROM expresssucshipmenttable1 WHERE shipmentTime BETWEEN fromDateTime AND toDateTime;
INSERT INTO shipmentQueryResultTable SELECT * FROM expresssucshipmenttable2 WHERE shipmentTime BETWEEN fromDateTime AND toDateTime;
INSERT INTO shipmentQueryResultTable SELECT * FROM expresssucshipmenttable3 WHERE shipmentTime BETWEEN fromDateTime AND toDateTime;
INSERT INTO shipmentQueryResultTable SELECT * FROM expresssucshipmenttable4 WHERE shipmentTime BETWEEN fromDateTime AND toDateTime;
INSERT INTO shipmentQueryResultTable SELECT * FROM expresssucshipmenttable5 WHERE shipmentTime BETWEEN fromDateTime AND toDateTime;
INSERT INTO shipmentQueryResultTable SELECT * FROM expresssucshipmenttable6 WHERE shipmentTime BETWEEN fromDateTime AND toDateTime;
INSERT INTO shipmentQueryResultTable SELECT * FROM expresssucshipmenttable7 WHERE shipmentTime BETWEEN fromDateTime AND toDateTime;
INSERT INTO shipmentQueryResultTable SELECT * FROM expresssucshipmenttable8 WHERE shipmentTime BETWEEN fromDateTime AND toDateTime;
INSERT INTO shipmentQueryResultTable SELECT * FROM expresssucshipmenttable9 WHERE shipmentTime BETWEEN fromDateTime AND toDateTime;
INSERT INTO shipmentQueryResultTable SELECT * FROM expresssucshipmenttable10 WHERE shipmentTime BETWEEN fromDateTime AND toDateTime;
INSERT INTO shipmentQueryResultTable SELECT * FROM expresssucshipmenttable11 WHERE shipmentTime BETWEEN fromDateTime AND toDateTime;
INSERT INTO shipmentQueryResultTable SELECT * FROM expresssucshipmenttable12 WHERE shipmentTime BETWEEN fromDateTime AND toDateTime;
INSERT INTO shipmentQueryResultTable SELECT * FROM expresssucshipmenttable13 WHERE shipmentTime BETWEEN fromDateTime AND toDateTime;
INSERT INTO shipmentQueryResultTable SELECT * FROM expresssucshipmenttable14 WHERE shipmentTime BETWEEN fromDateTime AND toDateTime;
INSERT INTO shipmentQueryResultTable SELECT * FROM expresssucshipmenttable15 WHERE shipmentTime BETWEEN fromDateTime AND toDateTime;
ELSEIF table_type = 2
THEN
INSERT INTO shipmentQueryResultTable SELECT * FROM expresstimeoutshipmenttable0 WHERE shipmentTime BETWEEN fromDateTime AND toDateTime;
INSERT INTO shipmentQueryResultTable SELECT * FROM expresstimeoutshipmenttable1 WHERE shipmentTime BETWEEN fromDateTime AND toDateTime;
INSERT INTO shipmentQueryResultTable SELECT * FROM expresstimeoutshipmenttable2 WHERE shipmentTime BETWEEN fromDateTime AND toDateTime;
INSERT INTO shipmentQueryResultTable SELECT * FROM expresstimeoutshipmenttable3 WHERE shipmentTime BETWEEN fromDateTime AND toDateTime;
INSERT INTO shipmentQueryResultTable SELECT * FROM expresstimeoutshipmenttable4 WHERE shipmentTime BETWEEN fromDateTime AND toDateTime;
INSERT INTO shipmentQueryResultTable SELECT * FROM expresstimeoutshipmenttable5 WHERE shipmentTime BETWEEN fromDateTime AND toDateTime;
INSERT INTO shipmentQueryResultTable SELECT * FROM expresstimeoutshipmenttable6 WHERE shipmentTime BETWEEN fromDateTime AND toDateTime;
INSERT INTO shipmentQueryResultTable SELECT * FROM expresstimeoutshipmenttable7 WHERE shipmentTime BETWEEN fromDateTime AND toDateTime;
INSERT INTO shipmentQueryResultTable SELECT * FROM expresstimeoutshipmenttable8 WHERE shipmentTime BETWEEN fromDateTime AND toDateTime;
INSERT INTO shipmentQueryResultTable SELECT * FROM expresstimeoutshipmenttable9 WHERE shipmentTime BETWEEN fromDateTime AND toDateTime;
INSERT INTO shipmentQueryResultTable SELECT * FROM expresstimeoutshipmenttable10 WHERE shipmentTime BETWEEN fromDateTime AND toDateTime;
INSERT INTO shipmentQueryResultTable SELECT * FROM expresstimeoutshipmenttable11 WHERE shipmentTime BETWEEN fromDateTime AND toDateTime;
INSERT INTO shipmentQueryResultTable SELECT * FROM expresstimeoutshipmenttable12 WHERE shipmentTime BETWEEN fromDateTime AND toDateTime;
INSERT INTO shipmentQueryResultTable SELECT * FROM expresstimeoutshipmenttable13 WHERE shipmentTime BETWEEN fromDateTime AND toDateTime;
INSERT INTO shipmentQueryResultTable SELECT * FROM expresstimeoutshipmenttable14 WHERE shipmentTime BETWEEN fromDateTime AND toDateTime;
INSERT INTO shipmentQueryResultTable SELECT * FROM expresstimeoutshipmenttable15 WHERE shipmentTime BETWEEN fromDateTime AND toDateTime;
END IF
ELSE
THEN
IF table_type = 1
THEN
16条insert语句
END
ELSEIF table_type = 2
THEN
INSERT INTO shipmentQueryResultTable SELECT * FROM expresstimeoutshipmenttable0 WHERE shipmentTime BETWEEN fromDateTime AND toDateTime AND shipmentID = shipmentID;
INSERT INTO shipmentQueryResultTable SELECT * FROM expresstimeoutshipmenttable1 WHERE shipmentTime BETWEEN fromDateTime AND toDateTime AND shipmentID = shipmentID;
INSERT INTO shipmentQueryResultTable SELECT * FROM expresstimeoutshipmenttable2 WHERE shipmentTime BETWEEN fromDateTime AND toDateTime AND shipmentID = shipmentID;
INSERT INTO shipmentQueryResultTable SELECT * FROM expresstimeoutshipmenttable3 WHERE shipmentTime BETWEEN fromDateTime AND toDateTime AND shipmentID = shipmentID;
INSERT INTO shipmentQueryResultTable SELECT * FROM expresstimeoutshipmenttable4 WHERE shipmentTime BETWEEN fromDateTime AND toDateTime AND shipmentID = shipmentID;
INSERT INTO shipmentQueryResultTable SELECT * FROM expresstimeoutshipmenttable5 WHERE shipmentTime BETWEEN fromDateTime AND toDateTime AND shipmentID = shipmentID;
INSERT INTO shipmentQueryResultTable SELECT * FROM expresstimeoutshipmenttable6 WHERE shipmentTime BETWEEN fromDateTime AND toDateTime AND shipmentID = shipmentID;
INSERT INTO shipmentQueryResultTable SELECT * FROM expresstimeoutshipmenttable7 WHERE shipmentTime BETWEEN fromDateTime AND toDateTime AND shipmentID = shipmentID;
INSERT INTO shipmentQueryResultTable SELECT * FROM expresstimeoutshipmenttable8 WHERE shipmentTime BETWEEN fromDateTime AND toDateTime AND shipmentID = shipmentID;
INSERT INTO shipmentQueryResultTable SELECT * FROM expresstimeoutshipmenttable9 WHERE shipmentTime BETWEEN fromDateTime AND toDateTime AND shipmentID = shipmentID;
INSERT INTO shipmentQueryResultTable SELECT * FROM expresstimeoutshipmenttable10 WHERE shipmentTime BETWEEN fromDateTime AND toDateTime AND shipmentID = shipmentID;
INSERT INTO shipmentQueryResultTable SELECT * FROM expresstimeoutshipmenttable11 WHERE shipmentTime BETWEEN fromDateTime AND toDateTime AND shipmentID = shipmentID;
INSERT INTO shipmentQueryResultTable SELECT * FROM expresstimeoutshipmenttable12 WHERE shipmentTime BETWEEN fromDateTime AND toDateTime AND shipmentID = shipmentID;
INSERT INTO shipmentQueryResultTable SELECT * FROM expresstimeoutshipmenttable13 WHERE shipmentTime BETWEEN fromDateTime AND toDateTime AND shipmentID = shipmentID;
INSERT INTO shipmentQueryResultTable SELECT * FROM expresstimeoutshipmenttable14 WHERE shipmentTime BETWEEN fromDateTime AND toDateTime AND shipmentID = shipmentID;
INSERT INTO shipmentQueryResultTable SELECT * FROM expresstimeoutshipmenttable15 WHERE shipmentTime BETWEEN fromDateTime AND toDateTime AND shipmentID = shipmentID;
END
END
END
ELSE
THEN
table_index = uin % 16;
IF table_type = 1
THEN
SET table_name = CONCAT('expresssucshipmenttable', CAST(table_index AS VARCHAR(4)));
ELSEIF table_type = 2
THEN
SET table_name = CONCAT('expresstimeoutshipmenttable',CAST(table_index AS VARCHAR(4)));
END IF
IF shipmentID = 0
THEN
SET @sqlstr = comcat('INSERT INTO shipmentQueryResultTable SELECT * FROM ',table_name ,
'WHERE shipmentTime between ', fromDateTime, " and ", toDateTime);
ELSE
THEN
SET @sqlstr = comcat('INSERT INTO shipmentQueryResultTable SELECT * FROM ',table_name ,
'WHERE (shipmentTime between ', fromDateTime, " and ", toDateTime, ")AND shipmentID=", shipmentID);
END IF
prepare stmt from @sqlstr;
execute stmt;
END IF
END IF
错误提示:1064-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 'DECLARE table_index.....if uin = 0 at line 5
DELETE FROM shipmentQueryResultTable;
DECLARE table_index int,table_name VARCHAR(50),stmt VARCHAR(2000);IF uin = 0
THEN
IF shipmentID = 0
THEN
IF table_type = 1
THEN
INSERT INTO shipmentQueryResultTable SELECT * FROM expresssucshipmenttable0 WHERE shipmentTime BETWEEN fromDateTime AND toDateTime;
INSERT INTO shipmentQueryResultTable SELECT * FROM expresssucshipmenttable1 WHERE shipmentTime BETWEEN fromDateTime AND toDateTime;
INSERT INTO shipmentQueryResultTable SELECT * FROM expresssucshipmenttable2 WHERE shipmentTime BETWEEN fromDateTime AND toDateTime;
INSERT INTO shipmentQueryResultTable SELECT * FROM expresssucshipmenttable3 WHERE shipmentTime BETWEEN fromDateTime AND toDateTime;
INSERT INTO shipmentQueryResultTable SELECT * FROM expresssucshipmenttable4 WHERE shipmentTime BETWEEN fromDateTime AND toDateTime;
INSERT INTO shipmentQueryResultTable SELECT * FROM expresssucshipmenttable5 WHERE shipmentTime BETWEEN fromDateTime AND toDateTime;
INSERT INTO shipmentQueryResultTable SELECT * FROM expresssucshipmenttable6 WHERE shipmentTime BETWEEN fromDateTime AND toDateTime;
INSERT INTO shipmentQueryResultTable SELECT * FROM expresssucshipmenttable7 WHERE shipmentTime BETWEEN fromDateTime AND toDateTime;
INSERT INTO shipmentQueryResultTable SELECT * FROM expresssucshipmenttable8 WHERE shipmentTime BETWEEN fromDateTime AND toDateTime;
INSERT INTO shipmentQueryResultTable SELECT * FROM expresssucshipmenttable9 WHERE shipmentTime BETWEEN fromDateTime AND toDateTime;
INSERT INTO shipmentQueryResultTable SELECT * FROM expresssucshipmenttable10 WHERE shipmentTime BETWEEN fromDateTime AND toDateTime;
INSERT INTO shipmentQueryResultTable SELECT * FROM expresssucshipmenttable11 WHERE shipmentTime BETWEEN fromDateTime AND toDateTime;
INSERT INTO shipmentQueryResultTable SELECT * FROM expresssucshipmenttable12 WHERE shipmentTime BETWEEN fromDateTime AND toDateTime;
INSERT INTO shipmentQueryResultTable SELECT * FROM expresssucshipmenttable13 WHERE shipmentTime BETWEEN fromDateTime AND toDateTime;
INSERT INTO shipmentQueryResultTable SELECT * FROM expresssucshipmenttable14 WHERE shipmentTime BETWEEN fromDateTime AND toDateTime;
INSERT INTO shipmentQueryResultTable SELECT * FROM expresssucshipmenttable15 WHERE shipmentTime BETWEEN fromDateTime AND toDateTime;
ELSEIF table_type = 2
THEN
INSERT INTO shipmentQueryResultTable SELECT * FROM expresstimeoutshipmenttable0 WHERE shipmentTime BETWEEN fromDateTime AND toDateTime;
INSERT INTO shipmentQueryResultTable SELECT * FROM expresstimeoutshipmenttable1 WHERE shipmentTime BETWEEN fromDateTime AND toDateTime;
INSERT INTO shipmentQueryResultTable SELECT * FROM expresstimeoutshipmenttable2 WHERE shipmentTime BETWEEN fromDateTime AND toDateTime;
INSERT INTO shipmentQueryResultTable SELECT * FROM expresstimeoutshipmenttable3 WHERE shipmentTime BETWEEN fromDateTime AND toDateTime;
INSERT INTO shipmentQueryResultTable SELECT * FROM expresstimeoutshipmenttable4 WHERE shipmentTime BETWEEN fromDateTime AND toDateTime;
INSERT INTO shipmentQueryResultTable SELECT * FROM expresstimeoutshipmenttable5 WHERE shipmentTime BETWEEN fromDateTime AND toDateTime;
INSERT INTO shipmentQueryResultTable SELECT * FROM expresstimeoutshipmenttable6 WHERE shipmentTime BETWEEN fromDateTime AND toDateTime;
INSERT INTO shipmentQueryResultTable SELECT * FROM expresstimeoutshipmenttable7 WHERE shipmentTime BETWEEN fromDateTime AND toDateTime;
INSERT INTO shipmentQueryResultTable SELECT * FROM expresstimeoutshipmenttable8 WHERE shipmentTime BETWEEN fromDateTime AND toDateTime;
INSERT INTO shipmentQueryResultTable SELECT * FROM expresstimeoutshipmenttable9 WHERE shipmentTime BETWEEN fromDateTime AND toDateTime;
INSERT INTO shipmentQueryResultTable SELECT * FROM expresstimeoutshipmenttable10 WHERE shipmentTime BETWEEN fromDateTime AND toDateTime;
INSERT INTO shipmentQueryResultTable SELECT * FROM expresstimeoutshipmenttable11 WHERE shipmentTime BETWEEN fromDateTime AND toDateTime;
INSERT INTO shipmentQueryResultTable SELECT * FROM expresstimeoutshipmenttable12 WHERE shipmentTime BETWEEN fromDateTime AND toDateTime;
INSERT INTO shipmentQueryResultTable SELECT * FROM expresstimeoutshipmenttable13 WHERE shipmentTime BETWEEN fromDateTime AND toDateTime;
INSERT INTO shipmentQueryResultTable SELECT * FROM expresstimeoutshipmenttable14 WHERE shipmentTime BETWEEN fromDateTime AND toDateTime;
INSERT INTO shipmentQueryResultTable SELECT * FROM expresstimeoutshipmenttable15 WHERE shipmentTime BETWEEN fromDateTime AND toDateTime;
END IF
ELSE
THEN
IF table_type = 1
THEN
16条insert语句
END
ELSEIF table_type = 2
THEN
INSERT INTO shipmentQueryResultTable SELECT * FROM expresstimeoutshipmenttable0 WHERE shipmentTime BETWEEN fromDateTime AND toDateTime AND shipmentID = shipmentID;
INSERT INTO shipmentQueryResultTable SELECT * FROM expresstimeoutshipmenttable1 WHERE shipmentTime BETWEEN fromDateTime AND toDateTime AND shipmentID = shipmentID;
INSERT INTO shipmentQueryResultTable SELECT * FROM expresstimeoutshipmenttable2 WHERE shipmentTime BETWEEN fromDateTime AND toDateTime AND shipmentID = shipmentID;
INSERT INTO shipmentQueryResultTable SELECT * FROM expresstimeoutshipmenttable3 WHERE shipmentTime BETWEEN fromDateTime AND toDateTime AND shipmentID = shipmentID;
INSERT INTO shipmentQueryResultTable SELECT * FROM expresstimeoutshipmenttable4 WHERE shipmentTime BETWEEN fromDateTime AND toDateTime AND shipmentID = shipmentID;
INSERT INTO shipmentQueryResultTable SELECT * FROM expresstimeoutshipmenttable5 WHERE shipmentTime BETWEEN fromDateTime AND toDateTime AND shipmentID = shipmentID;
INSERT INTO shipmentQueryResultTable SELECT * FROM expresstimeoutshipmenttable6 WHERE shipmentTime BETWEEN fromDateTime AND toDateTime AND shipmentID = shipmentID;
INSERT INTO shipmentQueryResultTable SELECT * FROM expresstimeoutshipmenttable7 WHERE shipmentTime BETWEEN fromDateTime AND toDateTime AND shipmentID = shipmentID;
INSERT INTO shipmentQueryResultTable SELECT * FROM expresstimeoutshipmenttable8 WHERE shipmentTime BETWEEN fromDateTime AND toDateTime AND shipmentID = shipmentID;
INSERT INTO shipmentQueryResultTable SELECT * FROM expresstimeoutshipmenttable9 WHERE shipmentTime BETWEEN fromDateTime AND toDateTime AND shipmentID = shipmentID;
INSERT INTO shipmentQueryResultTable SELECT * FROM expresstimeoutshipmenttable10 WHERE shipmentTime BETWEEN fromDateTime AND toDateTime AND shipmentID = shipmentID;
INSERT INTO shipmentQueryResultTable SELECT * FROM expresstimeoutshipmenttable11 WHERE shipmentTime BETWEEN fromDateTime AND toDateTime AND shipmentID = shipmentID;
INSERT INTO shipmentQueryResultTable SELECT * FROM expresstimeoutshipmenttable12 WHERE shipmentTime BETWEEN fromDateTime AND toDateTime AND shipmentID = shipmentID;
INSERT INTO shipmentQueryResultTable SELECT * FROM expresstimeoutshipmenttable13 WHERE shipmentTime BETWEEN fromDateTime AND toDateTime AND shipmentID = shipmentID;
INSERT INTO shipmentQueryResultTable SELECT * FROM expresstimeoutshipmenttable14 WHERE shipmentTime BETWEEN fromDateTime AND toDateTime AND shipmentID = shipmentID;
INSERT INTO shipmentQueryResultTable SELECT * FROM expresstimeoutshipmenttable15 WHERE shipmentTime BETWEEN fromDateTime AND toDateTime AND shipmentID = shipmentID;
END
END
END
ELSE
THEN
table_index = uin % 16;
IF table_type = 1
THEN
SET table_name = CONCAT('expresssucshipmenttable', CAST(table_index AS VARCHAR(4)));
ELSEIF table_type = 2
THEN
SET table_name = CONCAT('expresstimeoutshipmenttable',CAST(table_index AS VARCHAR(4)));
END IF
IF shipmentID = 0
THEN
SET @sqlstr = comcat('INSERT INTO shipmentQueryResultTable SELECT * FROM ',table_name ,
'WHERE shipmentTime between ', fromDateTime, " and ", toDateTime);
ELSE
THEN
SET @sqlstr = comcat('INSERT INTO shipmentQueryResultTable SELECT * FROM ',table_name ,
'WHERE (shipmentTime between ', fromDateTime, " and ", toDateTime, ")AND shipmentID=", shipmentID);
END IF
prepare stmt from @sqlstr;
execute stmt;
END IF
END IF
错误提示:1064-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 'DECLARE table_index.....if uin = 0 at line 5大神,救我啊http://bbs.csdn.net/topics/390520778
重新创建sp之后BEGIN
DECLARE a INT;
END直接就报1064错误了
create procedure xxx
BEGIN
DECLARE a INT;
END//
在之前我已经加上了delimiter //
但是还是报1064的错误
BEGIN
DECLARE a INT;
IF a=1 THEN SET a=0;
ELSEIF a=2 THEN SET a=3;
END IF;
END$$DELIMITER ;
delimiter //
create procedure test1()
BEGIN
DECLARE a INT;
SET a=0;
IF a=0
THEN
SET a=1;
ELSEIF a=1
SET a=0
END IF
END代码很简单,不知道为什么会报这个错误
DELIMITER $$DROP PROCEDURE IF EXISTS `test1`$$CREATE DEFINER=`root`@`localhost` PROCEDURE `test1`()
BEGIN
DECLARE a INT;
SET a=0;
IF a=0 THEN
SET a=1;
ELSEIF a=1 THEN
SET a=0;
END IF;
END$$DELIMITER ;
再问个问题 下面的字符串拼接报错 table_index为int类型 table_name定义为varchar(100)
SET table_name = CONCAT("expresssucshipmenttable", CAST(table_index AS VARCHAR(4)));