无法使用sequelize创建存储过程

时间:2021-11-11 02:22:05

I am running the following SQL query:

我正在运行以下SQL查询:

Executing (default): DROP PROCEDURE IF EXISTS x;

DELIMITER $$
CREATE PROCEDURE x()
BEGIN
    # do something
END $$
DELIMITER; $$

Like so:

sequelize.query(query, {
    type: sequelize.QueryTypes.SELECT
});

But I get this error (even though it works just fine, if I use any other SQL client):

但我得到这个错误(即使它工作得很好,如果我使用任何其他SQL客户端):

SequelizeDatabaseError: ER_PARSE_ERROR: 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 'DELIMITER $$

SequelizeDatabaseError:ER_PARSE_ERROR:SQL语法中有错误;检查与MySQL服务器版本对应的手册,以便在'DELIMITER $$附近使用正确的语法

CREATE PROCEDURE x()

CREATE PROCEDURE x()

BEGIN

I already added multipleStatements = true to my connection config, but it does not do anything.

我已经在我的连接配置中添加了multipleStatements = true,但它没有做任何事情。

Update

I ended up using RAW instead, like so:

我最终使用RAW,如下所示:

sequelize.query(query, {
    type: sequelize.QueryTypes.RAW
});

1 个解决方案

#1


Your error is actually in the last line. Take out the $$ after DELIMITER; The statement: "DELIMITER;" resets the delimiter to ";" the $$ after that confuses the syntax analyzer.

您的错误实际上在最后一行。在DELIMITER之后取出$$;声明:“DELIMITER;”将分隔符重置为“;”之后的$$混淆了语法分析器。

#1


Your error is actually in the last line. Take out the $$ after DELIMITER; The statement: "DELIMITER;" resets the delimiter to ";" the $$ after that confuses the syntax analyzer.

您的错误实际上在最后一行。在DELIMITER之后取出$$;声明:“DELIMITER;”将分隔符重置为“;”之后的$$混淆了语法分析器。