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!