Say you are writing a new stored procedure (for MySQL) and when you execute it, you get an error something like shown below - as you probably figured out all it means is that there is a syntax error with in the SQL. Often the error is misleading especially if it is a complicated query. One easy way to help narrow down the issue is to run it in a SQL Console which usually provides a better clue that can be your pointer to fixing the issue.

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘END’ at line 17 (errno: 1064). Click ‘Ignore’ if you’d like to have this error ignored until the end of the script.

If you run this script you will get the above error:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
DELIMITER $$
 
DROP PROCEDURE IF EXISTS `someSchema`.`sp_someSP`$$
CREATE  DEFINER=`someUser`@`someServer` PROCEDURE `someSchema`.`sp_someSP` (
    in uavname varchar(20)
)
BEGIN
SELECT u.id, i.*, ll.*, g.*, c.*
FROM    uav as u,
    imu as i,
        uav_ll as ll,
        gps as g,
        uav_controller as c
WHERE
    u.name = uavname and
        u.id = i.uav_id and
        u.id = ll.uav_id and
        u.id = g.uav_id and
        u.id = c.uav_id
END$$
 
DELIMITER ;

The main issue in my example above was that a delimiter (semi-colon in this case) was missing where the SQL statement finishes i.e. in the last WHERE condition. Here is a snippet of what the updated WHERE clause should look like.

1
2
3
4
5
6
7
WHERE
    u.name = uavname and
        u.id = i.uav_id and
        u.id = ll.uav_id and
        u.id = g.uav_id and
        u.id = c.uav_id ; -- semicolon added here
END$$