gpt4 book ai didi

mysql - 存储过程语法

转载 作者:行者123 更新时间:2023-11-30 00:25:00 25 4
gpt4 key购买 nike

我想使用 MySQL 编写一个存储过程,让我可以使用参数插入、更新或删除到 persona 的表中,该表具有 id_persona、nombres、apellidos 和 edad 字段;那么你能告诉我为什么我的存储过程是错误的吗?

DELIMITER $$
DROP PROCEDURE IF EXISTS guardarPersona$$
CREATE PROCEDURE persona(input_id_persona INT, input_nombres VARCHAR(100), input_apellidos VARCHAR(100), input_edad INT, input_accion VARCHAR(15))
BEGIN
IF (input_accion='guardar') THEN
INSERT INTO `persona`(`nombres`, `apellidos`, `edad`) VALUES (input_nombres,input_apellidos,input_edad);
ELSEIF (input_accion='modificar') THEN
UPDATE `persona` SET `nombres`=input_nombres,`apellidos`=input_apellidos,`edad`=input_edad WHERE id_persona = input_id_persona;
ELSEIF (input_accion='eliminar') THEN
DELETE FROM `persona` WHERE id_persona = input_id_persona;
ELSE
mysql_error();
END IF;
END $$
DELIMITER ;

这是mysql错误......

MySQL ha dicho: Documentación

1064 - 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 '();

END IF; END' at line 10

最佳答案

mysql_error()函数在API中使用。

要获取存储过程中的错误数据,您应该使用 SHOW ERRORS;

...
ELSE
SHOW ERRORS;
END IF;
....

关于mysql - 存储过程语法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22953192/

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