这是我的代码。
CREATE PROCEDURE add_new_user(IN VARCHAR(30) UName)
BEGIN
INSERT INTO `tbl_user_details` (`Name`) VALUES(UName);
END
我运行此查询时显示错误
错误代码:1064 您的SQL语法有误;检查与您的MariaDB服务器版本相对应的手册以获取正确的语法,以在第1行的“ END”附近使用
请给我更正。
答案 0 :(得分:1)
如果该过程中只有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)
答案 1 :(得分:0)
DELIMITER//
USE db_name//
CREATE PROCEDURE add_new_user(IN UName VARCHAR(30))
BEGIN
INSERT INTO `tbl_user_details` (`Name`) VALUES(UName);
END//
DELIMITER ;