gpt4 book ai didi

mysql - $$DELIMITER 附近的语法错误

转载 作者:行者123 更新时间:2023-11-29 05:13:50 24 4
gpt4 key购买 nike

我在创建存储过程时遇到错误,它说我有语法错误,但我找不到它在哪里...

MySql 错误:

"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

CREATE PROCEDURE 'entradas_sai'(IN ID_VEICULO VARCHAR(45), OUT' at line 1

下面是与题目相关的代码:

$$DELIMITERCREATE PROCEDURE 'entradas_sai'(IN ID_VEICULO VARCHAR(45), OUT retcode INT)BEGIN    DECLARE '_rollback' BOOL DEFAULT 0;    DECLARE CONTINUE HANDLER FOR SQLEXCEPTION SET '_rollback' = 1;    START TRANSACTION;    INSERT INTO SAIDAS(data, hora) VALUES(CURDATE("yyyy-MM-dd"),CURTIME("hh:mm:ss))    UPDATE ENTRADAS(SAI) WITH VALUES(@SAI)    IF '_rollback' THEN        SET retcode = 0;        ROLLBACK;    ELSE        SET retcode = 1;        COMMIT;    END IF;END$$DELIMITER ;

Here is a screenshot of my MySqlWB:

MySql WorkBench

EDIT:Here is the log:

>Executing:
>USE `portaria`;
>DROP unknown IF EXISTS `unknown_SYNTAX_ERROR`;
>
>DELIMITER $$
>USE `portaria`$$
>DELIMITER $$
>
>CREATE PROCEDURE 'entradas_sai'(
>IN ID_VEICULO VARCHAR(45), OUT retcode INT)
>BEGIN
> DECLARE '_rollback' BOOL DEFAULT 0;
> DECLARE CONTINUE HANDLER FOR SQLEXCEPTION SET '_rollback' = 1;
> START TRANSACTION;
> INSERT INTO SAIDAS(data, hora) VALUES(date(now()) ,time(now()))
> UPDATE ENTRADAS(SAI) WITH VALUES(@SAI)
> IF '_rollback' THEN
> SET retcode = 0;
> ROLLBACK;
> ELSE
> SET retcode = 1;
> COMMIT;
> END IF;
>END$$
>
>DELIMITER ;$$
>
>DELIMITER ;
>
>ERROR 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 >'unknown IF EXISTS `unknown_SYNTAX_ERROR`' at line 1
>SQL Statement:
>DROP unknown IF EXISTS `unknown_SYNTAX_ERROR`

在这里,我得到了我希望我的程序执行的操作的场景...

I have a table called "Entradas" and one called "Saidas". Both have the column "data" and "hora". With that in mind, since the "data" and "hora column of "entradas" mean that a car joined at that date and time, and the values from the columns "data" and "hora" of "saidas" are mean to be inserted as i click a button, inserting the current date and time. I'm requesting a sql syntax that could insert the values "data" and "hora" into the table "saidas" and update a value of "entradas" called "sai" which is equal to 0 and i want it to change to 1 on button press... Any sugestion?

最佳答案

分隔符 ($$) 出现在 DELIMITER 关键字之后。还使用 date(now()) 代替 CURDATE("yyyy-MM-dd")time(now()) 代替 CURTIME("hh:mm:ss"))试试这个

DELIMITER $$
CREATE PROCEDURE `entradas_sai`(IN ID_VEICULO VARCHAR(45), OUT retcode INT)
BEGIN
DECLARE _rollback boolean DEFAULT 0;
DECLARE CONTINUE HANDLER FOR SQLEXCEPTION SET _rollback = 1;
START TRANSACTION;
INSERT INTO SAIDAS(data, hora) VALUES(date(now()) ,time(now()));
UPDATE ENTRADAS SET SAI = @SAI;
IF _rollback = 1 THEN
SET retcode = 0;
ROLLBACK;
ELSE
SET retcode = 1;
COMMIT;
END IF;
END$$

DELIMITER ;

关于mysql - $$DELIMITER 附近的语法错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35840487/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com