存储过程插入查询

mspsb9vt  于 2021-06-20  发布在  Mysql
关注(0)|答案(2)|浏览(382)

这是我的密码。

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

当我运行这个查询时,它显示一个错误
错误代码:1064您的sql语法有错误;检查与您的mariadb服务器版本相对应的手册,以便在第1行的“end”附近使用正确的语法
请给我更正一下。

dbf7pr2w

dbf7pr2w1#

如果过程中只有一条语句,则不需要设置分隔符或使用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)
xiozqbni

xiozqbni2#

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

相关问题