Home >Database >Mysql Tutorial >How to resolve the MySQL error 'There is an error in your SQL syntax; check the manual for your MySQL server version to learn the correct syntax to use?'

How to resolve the MySQL error 'There is an error in your SQL syntax; check the manual for your MySQL server version to learn the correct syntax to use?'

王林
王林forward
2023-09-08 23:21:111723browse

如何解决 MySQL 错误“您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,以了解要使用的正确语法?”

To avoid such errors in MySQL stored procedures, you need to change the delimiter; to //.

Suppose if you are using stored procedures or triggers or even functions then you need to change the delimiter. The syntax is as follows.

DELIMITER //
   CREATE PROCEDURE yourProcedureName()
   BEGIN
      Statement1,
      .
      .
   N
END;
//
DELIMITER ;

To understand the above syntax, let us create a stored procedure. The query to create a stored procedure is as follows -

mysql> DELIMITER //
mysql> CREATE PROCEDURE sp_getAllRecords()
-> BEGIN
-> SELECT *FROM employeetable;
-> END;
-> //
Query OK, 0 rows affected (0.23 sec)
mysql> DELIMITER ;

Use the CALL command to call the stored procedure. The syntax is as follows.

CALL yourStoredProcedureName();

Now call the above procedure to return all records of the Employee table. The query is as follows.

mysql> CALL sp_getAllRecords();

The following is the output.

+------------+--------------+----------------+
| EmployeeId | EmployeeName | EmployeeSalary |
+------------+--------------+----------------+
| 2 | Bob | 1000 |
| 3 | Carol | 2500 |
+------------+--------------+----------------+
2 rows in set (0.00 sec)
Query OK, 0 rows affected (0.02 sec)

The above is the detailed content of How to resolve the MySQL error 'There is an error in your SQL syntax; check the manual for your MySQL server version to learn the correct syntax to use?'. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete