语法错误:1064,创建存储过程时

时间:2022-02-01 01:38:18
CREATE table parent_user
 ( userid int  auto_increment PRIMARY KEY,
 Username varchar(100) NOT NULL,
    Password varchar(200) NOT NULL,
    Email varchar(200) NOT NULL

 );

EDIT : OK so I made some changes:

编辑:好的,所以我做了一些改变:

CREATE PROCEDURE `parent_reg` (
pUserName varchar(100)
pPassword varchar(200)
pEmail varchar(200)
)
as
Begin
Declare Count int
Declare ReturnCode int

Select Count = Count(Username)
from parent_user where Username = @Username
If Count > 0
Begin
      Set ReturnCode = -1
    End
    Else
    Begin 
      Set ReturnCode = 1
      insert into parent_user values
      (pUserName, pPassword, pEmail)
    End
    Select pReturnCode as ReturnValue 
    End

But I still got the same error- 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 'pPassword varchar(200) pEmail varchar(200) ) ....'

但我仍然得到相同的错误 - 错误1064:您的SQL语法中有错误;检查与您的MySQL服务器版本对应的手册,以便在'pPassword varchar(200)pEmail varchar(200)附近使用正确的语法....“

The syntax error is at 'pPassword varchar(200)'

语法错误位于'pPassword varchar(200)'

2 个解决方案

#1


0  

This is invalid syntax for MySQL Stored Procedure. The code you posted looks more like Microsoft SQL Server (Transact SQL) syntax.

这是MySQL存储过程的无效语法。您发布的代码看起来更像Microsoft SQL Server(Transact SQL)语法。

Some observations:

一些观察:

MySQL procedure variables cannot start with @. (That character is reserved for user-defined variables.)

MySQL过程变量不能以@开头。 (该字符保留给用户定义的变量。)

MySQL doesn't use a NVARCHAR type. I believe it's the setting of the character_set_client variable in the session (at the time the procedure is created) is what controls the characterset of the procedure variables.

MySQL不使用NVARCHAR类型。我相信会话中的character_set_client变量的设置(在创建过程时)是控制过程变量的字符集的。

The line select * from parent_user, before the CREATE PROCEDURE looks entirely out of place.

在CREATE PROCEDURE看起来完全不合适之前,行select_来自parent_user。

Missing semicolons. The INSERT is for a table with four columns, but only three values, and there's no column list. Lots of other oddly bizarre syntax.

缺少分号。 INSERT用于包含四列的表,但只有三个值,并且没有列列表。很多其他奇怪的奇怪语法。

If your goal is to create a stored procedure in MySQL, you'd need syntax closer to this:

如果你的目标是在MySQL中创建一个存储过程,你需要更接近这个的语法:

DELIMITER $$

CREATE PROCEDURE parent_reg(p_username VARCHAR(100),
p_password VARCHAR(200), p_email VARCHAR(200)
)
BEGIN
  DECLARE mycount INT;
  DECLARE myreturncode INT;

  SELECT COUNT(pu.username)
    INTO mycount
    FROM `parent_user` pu
   WHERE pu.username = p_username;

  IF (mycount > 0 ) THEN
    SET myreturncode = -1;
  ELSE
    SET myreturncode = 1;
    INSERT INTO `parent_user` (`username`, `password`, `email`)
    VALUES (p_username, p_password, p_email);
  END IF;
  SELECT myreturncode AS `ReturnValue`;
END$$

DELIMITER ;

#2


0  

Maybe it's your database's collation. When installing SQL Server and choose your default collation, there's a "case sensitivity" checkbox. Certain collations are case sensitive and will affect your queries (and stored procedures).

也许这是你的数据库整理。安装SQL Server并选择默认排序规则时,会出现“区分大小写”复选框。某些排序规则区分大小写,会影响您的查询(和存储过程)。

A lot of vendors don't test their products on servers with case sensitive collations, which leads to runtime errors.

许多供应商不会在具有区分大小写的排序规则的服务器上测试他们的产品,这会导致运行时错误。

So just try to choose between "Username" and "UserName"

所以只需尝试在“用户名”和“用户名”之间进行选择

#1


0  

This is invalid syntax for MySQL Stored Procedure. The code you posted looks more like Microsoft SQL Server (Transact SQL) syntax.

这是MySQL存储过程的无效语法。您发布的代码看起来更像Microsoft SQL Server(Transact SQL)语法。

Some observations:

一些观察:

MySQL procedure variables cannot start with @. (That character is reserved for user-defined variables.)

MySQL过程变量不能以@开头。 (该字符保留给用户定义的变量。)

MySQL doesn't use a NVARCHAR type. I believe it's the setting of the character_set_client variable in the session (at the time the procedure is created) is what controls the characterset of the procedure variables.

MySQL不使用NVARCHAR类型。我相信会话中的character_set_client变量的设置(在创建过程时)是控制过程变量的字符集的。

The line select * from parent_user, before the CREATE PROCEDURE looks entirely out of place.

在CREATE PROCEDURE看起来完全不合适之前,行select_来自parent_user。

Missing semicolons. The INSERT is for a table with four columns, but only three values, and there's no column list. Lots of other oddly bizarre syntax.

缺少分号。 INSERT用于包含四列的表,但只有三个值,并且没有列列表。很多其他奇怪的奇怪语法。

If your goal is to create a stored procedure in MySQL, you'd need syntax closer to this:

如果你的目标是在MySQL中创建一个存储过程,你需要更接近这个的语法:

DELIMITER $$

CREATE PROCEDURE parent_reg(p_username VARCHAR(100),
p_password VARCHAR(200), p_email VARCHAR(200)
)
BEGIN
  DECLARE mycount INT;
  DECLARE myreturncode INT;

  SELECT COUNT(pu.username)
    INTO mycount
    FROM `parent_user` pu
   WHERE pu.username = p_username;

  IF (mycount > 0 ) THEN
    SET myreturncode = -1;
  ELSE
    SET myreturncode = 1;
    INSERT INTO `parent_user` (`username`, `password`, `email`)
    VALUES (p_username, p_password, p_email);
  END IF;
  SELECT myreturncode AS `ReturnValue`;
END$$

DELIMITER ;

#2


0  

Maybe it's your database's collation. When installing SQL Server and choose your default collation, there's a "case sensitivity" checkbox. Certain collations are case sensitive and will affect your queries (and stored procedures).

也许这是你的数据库整理。安装SQL Server并选择默认排序规则时,会出现“区分大小写”复选框。某些排序规则区分大小写,会影响您的查询(和存储过程)。

A lot of vendors don't test their products on servers with case sensitive collations, which leads to runtime errors.

许多供应商不会在具有区分大小写的排序规则的服务器上测试他们的产品,这会导致运行时错误。

So just try to choose between "Username" and "UserName"

所以只需尝试在“用户名”和“用户名”之间进行选择