gpt4 book ai didi

mysql - 存储过程插入查询

转载 作者:行者123 更新时间:2023-11-29 10:05:17 25 4
gpt4 key购买 nike

这是我的代码。

CREATE PROCEDURE add_new_user(IN VARCHAR(30) UName)
BEGIN
INSERT INTO `tbl_user_details` (`Name`) VALUES(UName);
END

当我运行此查询时,它显示错误

错误代码:1064您的 SQL 语法有错误;检查与您的 MariaDB 服务器版本对应的手册,了解在第 1 行“END”附近使用的正确语法

请给我更正。

最佳答案

如果过程中只有 1 条语句,则无需设置分隔符或使用 begin..end 语句。

MariaDB [sandbox]> drop procedure if exists p;
Query OK, 0 rows affected (0.00 sec)

MariaDB [sandbox]> CREATE PROCEDURE p(IN UName VARCHAR(30) )
-> INSERT INTO `tbl_user_details` (`Name`) VALUES(UName);
Query OK, 0 rows affected (0.00 sec)

MariaDB [sandbox]> show create procedure p;
+-----------+--------------------------------------------+------------------------------------------------------------------------------------------------------------------------------+----------------------+----------------------+--------------------+
| Procedure | sql_mode | Create Procedure | character_set_client | collation_connection | Database Collation |
+-----------+--------------------------------------------+------------------------------------------------------------------------------------------------------------------------------+----------------------+----------------------+--------------------+
| p | STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION | CREATE DEFINER=`root`@`localhost` PROCEDURE `p`(IN UName VARCHAR(30) )
INSERT INTO `tbl_user_details` (`Name`) VALUES(UName) | cp850 | cp850_general_ci | latin1_swedish_ci |
+-----------+--------------------------------------------+------------------------------------------------------------------------------------------------------------------------------+----------------------+----------------------+--------------------+
1 row in set (0.00 sec)

关于mysql - 存储过程插入查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52037662/

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