MySQL 错误:您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,了解在附近使用的正确语法

发布于 2024-11-01 17:51:56 字数 286 浏览 10 评论 0原文

我有这样的存储过程:

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

但它给出了错误:

#1064 - 您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,了解在第 3 行 '' 附近使用的正确语法

该错误是什么意思?第 2 行有什么问题?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

林空鹿饮溪 2024-11-08 17:51:56

在使用触发器、存储过程等之前必须更改分隔符。

delimiter //
create procedure ProG() 
begin 
SELECT * FROM hs_hr_employee_leave_quota;
end;//
delimiter ;

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 ;
尾戒 2024-11-08 17:51:56

如何找出此 MySQL 错误试图说明的内容:

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

此错误中没有任何线索。您必须仔细检查所有这些项目,看看您的错误在哪里:

  1. 您省略了或包含了不必要的符号:!@#$%^&*()-_=+[]{}\| ;:'",<>/?
  2. 放错位置、缺失或不必要的关键字:selectinto 或无数其他关键字。
  3. 您有一些 unicode 字符看起来像查询中的 ASCII 字符,但实际上不是 不匹配
  4. 关键字之间的错位、缺失或不必要的空格或换行符。
  5. 的单引号、双引号、括号或大括号

将尽可能多地从损坏的查询中删除,直到下次它开始工作为止。语法报告系统。

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.

绝對不後悔。 2024-11-08 17:51:56

分隔符,分隔符...

当程序中有多个语句时,您确实需要它们。 (换句话说,您的代码中是否有 ; 以及更多语句/命令?那么,您需要使用分隔符)。

对于像你这样简单的程序,你可以这样做:

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

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`;
筑梦 2024-11-08 17:51:56

这可能是 mysql 的内存问题
尝试增加 my.ini 中的 max_allowed_pa​​cket

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

静谧幽蓝 2024-11-08 17:51:56

MYSQL PROCEDURE 步骤:

  1. 更改默认的分隔符'; ' 到 '// '

分隔符 //

  1. 创建PROCEDURE,可以参考语法< /a>

    注意:不要忘记以 ' 结束语句; '

创建过程ProG() 
开始 
从 hs_hr_employee_leave_quota 中选择*;
结尾;//
  1. 将分隔符更改回“;

分隔符;

  1. 现在执行:

调用 ProG();

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();

白云悠悠 2024-11-08 17:51:56

我得到了同样的错误如下:

错误 1064 (42000):您的 SQL 语法有错误;检查
与您的 MySQL 服务器版本相对应的手册
第 3 行 ')' 附近使用的语法

当使用尾随逗号时,如下所示:

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

因此,我删除了尾随逗号,如下所示,然后错误得到解决:

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

而且,我也遇到了以下相同的错误:

错误 1064 (42000):您的 SQL 语法有错误;检查
与您的 MySQL 服务器版本相对应的手册
在第 1 行的“count( num int )”附近使用的语法

count( 之间没有空格时,如下所示,因为它被识别为 count() 这是MySQL中的内置函数:

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

所以,我在 count( 之间留了一个空格,如下所示,然后错误就解决了:

          -- Make a space
                  ↓
create table count (
  num int
);

而且,我也得到了下面同样的错误:

错误 1064 (42000):您的 SQL 语法有错误;检查
与您的 MySQL 服务器版本相对应的手册
在第 1 行 'person TO 'john'@'localhost'' 附近使用的语法

当我给出 对所有数据库 (*.person) 中的用户 johnperson 表的 PROCESS 权限code> 与 GRANT 通过使用用户 登录root 如下所示:

GRANT PROCESS ON *.person TO 'john'@'localhost';

因此,我对所有数据库(*.*)中的所有表授予了 PROCESS 权限,如下所示,然后我可以解决错误。 *我的回答解释它更多:

GRANT PROCESS ON *.* TO 'john'@'localhost';

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
);

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 'person TO 'john'@'localhost'' at line 1

When I gave PROCESS privilege on only person table in all databases (*.person) to the user john with GRANT by login with the user root as shown below:

GRANT PROCESS ON *.person TO 'john'@'localhost';

So, I gave PROCESS privilege on all the tables in all databases (*.*) as shown below, then I could solve the error. *My answer explains it more:

GRANT PROCESS ON *.* TO 'john'@'localhost';
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文