35

I have the Stored procedure like this:

CREATE PROCEDURE ProG()
  BEGIN
    SELECT * FROM `hs_hr_employee_leave_quota`;
  END

But it gives the error:

#1064 - 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 '' at line 3

What does the error mean? What is wrong with line number 2?

Super Kai - Kazuya Ito
  • 22,221
  • 10
  • 124
  • 129
Gnanendra
  • 509
  • 3
  • 9
  • 12

6 Answers6

59

You have to change delimiter before using triggers, stored procedures and so on.

delimiter //
create procedure ProG() 
begin 
SELECT * FROM hs_hr_employee_leave_quota;
end;//
delimiter ;
Nicola Cossu
  • 54,599
  • 15
  • 92
  • 98
17

How to find out what this MySQL Error is trying to say:

#1064 - You have an error in your SQL syntax;

This error has no clues in it. You have to double check all of these items to see where your mistake is:

  1. You have omitted, or included an unnecessary symbol: !@#$%^&*()-_=+[]{}\|;:'",<>/?
  2. A misplaced, missing or unnecessary keyword: select, into, or countless others.
  3. You have unicode characters that look like ascii characters in your query but are not recognized.
  4. Misplaced, missing or unnecessary whitespace or newlines between keywords.
  5. Unmatched single quotes, double quotes, parenthesis or braces.

Take away as much as you can from the broken query until it starts working. And then use PostgreSQL next time that has a sane syntax reporting system.

Eric Leschinski
  • 146,994
  • 96
  • 417
  • 335
6

Delimiters, delimiters...

You really need them when there are multiple statements in your procedure. (in other words, do you have a ; in your code and then more statements/commands? Then, you need to use delimiters).

For such a simpler rpocedure as yours though, you could just do:

CREATE PROCEDURE ProG()
  SELECT * FROM `hs_hr_employee_leave_quota`;
ypercubeᵀᴹ
  • 113,259
  • 19
  • 174
  • 235
0

This might be a memmory issue on mysql try to increase max_allowed_packet in my.ini

sherin.k
  • 63
  • 10
  • This does not provide an answer to the question. Once you have sufficient [reputation](http://stackoverflow.com/help/whats-reputation) you will be able to [comment](http://stackoverflow.com/help/privileges/comment) on any post. Also check this [what can I do instead](https://meta.stackexchange.com/questions/214173/why-do-i-need-50-reputation-to-comment-what-can-i-do-instead). – thewaywewere Jun 15 '17 at 07:12
0

MYSQL PROCEDURE steps:

  1. change delimiter from default ' ; ' to ' // '

DELIMITER //

  1. create PROCEDURE, you can refer syntax

    NOTE: Don't forget to end statement with ' ; '

create procedure ProG() 
begin 
SELECT * FROM hs_hr_employee_leave_quota;
end;//
  1. Change delimiter back to ' ; '

delimiter ;

  1. Now to execute:

call ProG();

Abhi
  • 995
  • 1
  • 8
  • 12
0

I got the same error below:

ERROR 1064 (42000): 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 ')' at line 3

When using a trailing comma as shown below:

create table person(
  name varchar(50),
);             -- ↑ A trailing comma

So, I removed the trailing comma as shown below, then the error was solved:

create table person(
  name varchar(50)
);             -- ↑ No trailing comma

And, I also got the same error below:

ERROR 1064 (42000): 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 'count( num int )' at line 1

When there is no space between "count" and "(" as shown below because it's recognized as "count()" which is the built-in function in MySQL:

            -- No space
                 ↓
create table count(
  num int
);

So, I made a space between "count" and "(" as shown below, then the error was solved:

          -- Make a space
                  ↓
create table count (
  num int
);
Super Kai - Kazuya Ito
  • 22,221
  • 10
  • 124
  • 129