我有一个带有过程的名为procedure.sql的Sql文件。 Maria DB版本:服务器版本:10.0.29-MariaDB-0ubuntu0.16.04.1 Ubuntu 16.04
但我得到ERROR AS Follows:
>mysql -u root -p XXX < /home/azure/Downloads/procedure.sql
>Enter password:
>ERROR 1064 (42000) at line 2: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '();
>USE XXX;
>CREATE OR REPLACE PROCEDURE XXX.updateDoc_StorageID ()
>BEGIN' at line 1
有人可以帮我吗?
procedure.sql代码:
DELIMITER //
DROP PROCEDURE IF EXISTS XXX.updateDoc_StorageID;
USE XXX;
CREATE OR REPLACE PROCEDURE XXX.updateDoc_StorageID ()
BEGIN
DECLARE myTransacID INT DEFAULT 0;
DECLARE myTransProductId INT DEFAULT 0;
DECLARE myDocStoreID VARCHAR(500) DEFAULT '0';
DECLARE my_count INT DEFAULT 0;
DECLARE trans_csr CURSOR FOR SELECT 1,2 FROM MainTable ORDER BY TransactionID;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET my_count=1;
SET my_count=0;
OPEN trans_csr;
trans_loop:LOOP
FETCH trans_csr INTO myTransacID,myTransProductId;
IF my_count=1 THEN
LEAVE trans_loop;
END IF;
If(myTransProductId=8)
then
if exists(....)
then
.......
end if;
elseif (myTransProductId=11)
then
if exists(........)
then
.......
END IF;
END IF;
END LOOP trans_loop;
CLOSE trans_csr;
SET my_count=0;
END;
//
DELIMITER ;
我得到的参考来自: https://mariadb.com/kb/en/mariadb/create-procedure/
答案 0 :(得分:0)
语法错误不适用于CREATE PROCEDURE
,它适用于前面的DROP PROCEDURE
,您不应该在那里使用括号。
DROP PROCEDURE IF EXISTS XXX.updateDoc_StorageID;
第二个错误如下,因为该过程尚未被删除,它仍然存在。
另外,修复分隔符 - 如果您在开始时设置$$
,则每个进一步的查询都应以$$
结尾,而不是以分号结尾。
答案 1 :(得分:0)
版本10.0.x StoredProcedure的正确语法将是:
DELIMITER //
DROP PROCEDURE IF EXISTS XXX.updateDoc_StorageID;
USE XXX;
CREATE OR REPLACE PROCEDURE XXX.updateDoc_StorageID ()
BEGIN
DECLARE myTransacID INT DEFAULT 0;
DECLARE myTransProductId INT DEFAULT 0;
DECLARE myDocStoreID VARCHAR(500) DEFAULT '0';
DECLARE my_count INT DEFAULT 0;
DECLARE trans_csr CURSOR FOR SELECT 1,2 FROM MainTable ORDER BY TransactionID;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET my_count=1;
SET my_count=0;
OPEN trans_csr;
trans_loop:LOOP
FETCH trans_csr INTO myTransacID,myTransProductId;
IF my_count=1 THEN
LEAVE trans_loop;
END IF;
If(myTransProductId=8)
then
if exists(....)
then
.......
end if;
elseif (myTransProductId=11)
then
if exists(........)
then
.......
END IF;
END IF;
END LOOP trans_loop;
CLOSE trans_csr;
SET my_count=0;
END;
//
DELIMITER ;