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?'

王林
Release: 2023-09-08 23:21:11
forward
1663 people have browsed it

如何解决 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 ;
Copy after login

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 ;
Copy after login

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

CALL yourStoredProcedureName();
Copy after login

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

mysql> CALL sp_getAllRecords();
Copy after login

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)
Copy after login

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!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template