1

我正在尝试创建此过程

CREATE PROCEDURE RequestApproval (
  IN occupation enum('professor', 'student', 'pastor'),
  IN organization varchar(500),
  IN lastName varchar(100),
  IN firstName varchar(100),
  IN email varchar(300),
  IN phone varchar(50),
  IN description varchar(10000)
)
BEGIN
INSERT INTO `Discounts`(`Occupation`, 
  `Organization`, 
  `LastName`, 
  `FirstName`, 
  `Email`, 
  `Phone`, 
  `Description`) 
VALUES (occupation, 
  organization, 
  lastName, 
  firstName, 
  email, 
  phone, 
  description);
END ;

我收到了这个错误

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

当它只是说空字符串()附近存在无效语法时,我不知道要更改什么''。它不会告诉我无效令牌是什么——我做错了什么?

4

3 回答 3

3

看起来您需要设置一个备用分隔符。以下将使用DELIMITER关键字与 MySQL 命令行客户端一起使用,但其他客户端有自己的指定分隔符的方法。

/* set alternate delimiter $$ */
DELIMITER $$
CREATE PROCEDURE RequestApproval (
  IN occupation enum('professor', 'student', 'pastor'),
  IN organization varchar(500),
  IN lastName varchar(100),
  IN firstName varchar(100),
  IN email varchar(300),
  IN phone varchar(50),
  IN description varchar(10000)
)
BEGIN
/* Use regular delimiter ; in the statement */
INSERT INTO `Discounts`(`Occupation`, `Organization`, `LastName`, `FirstName`, `Email`, `Phone`, `Description`) VALUES (occupation, organization, lastName, firstName, email, phone, description);
/* end the procedure with the alternate delimiter */
END$$
/* reset to ; */
DELIMITER ;

它在第 11 行报告了一个没有特定字符的语法错误,可能是因为它;将该行上END

于 2012-05-31T13:04:19.767 回答
1

尝试设置分隔符,过程结束时将使用 DELIMITER 而不是;看我的示例我更改插入以使其在我的本地主机中

mysql> delimiter \\

jcho360> CREATE PROCEDURE RequestApproval (
    ->   IN occupation enum('professor', 'student', 'pastor'),
    ->   IN organization varchar(500),
    ->   IN lastName varchar(100),
    ->   IN firstName varchar(100),
    ->   IN email varchar(300),
    ->   IN phone varchar(50),
    ->   IN description varchar(10000)
    -> )
    -> BEGIN
    -> INSERT INTO `t1` VALUES (0, lastName, firstName, 0);
    -> END //
Query OK, 0 rows affected (0.00 sec)

jcho360> delimiter ;
于 2012-05-31T13:05:21.467 回答
0

If its NOT the delimiter as others have mentioned, and since I don't have MySQL available here, I would hedge to think that it's getting confused with your parameters vs the column names. You are trying to insert into X ( someColumn ) values ( someColumn )... is it interpreting it the "Values" portion as the column name, or the parameter.

I would try changing the parameters to

pOccupation, pOrganization, pLastName, etc...

then your insert to be

insert into YourTable ( Occupation, Organization, etc... )
   values ( pOccupation, pOrganization, etc... )

Then no ambiguity of what MIGHT be taking place under the hood.

于 2012-05-31T13:08:46.423 回答