1

我有这个 MySQL 查询来创建一个存储过程:

Delimiter //;
Create Procedure addUser(
    IN facebookId varchar(20), 
        IN name varchar(50), 
        In accessToken varchar(100), 
        in expires float)
Begin
    Declare invitingUsers Table(Id varchar(20));

        Insert Into Users 
        (`Facebook_Id`,`Name`,`Access_Token`,`Expired`) Values (facebookId,name,accessToken,expires);

        Select Inviting_Id 
        From Invited_Users
        Where Invited_Id = facebookId
        Into invitingUsers;

        Update Table Users 
        Set Credit = Credit + 1 
        Where Facebook_Id In (Select Id From invitingUsers);
End//

但我不断收到此错误 - 不明白为什么:

#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 'Table(Id varchar(20)); Insert Into Users (`Facebook' at line 7
4

1 回答 1

2

改变 #1

Delimiter //;Delimiter //

改变 #2

在内存中创建临时表

改变#3

改变了

Select Inviting_Id 
From Invited_Users
Where Invited_Id = facebookId
Into invitingUsers;

进入

INSERT INTO invitingUsers          
Select Inviting_Id From Invited_Users
Where Invited_Id = facebookId;

通过这些更改,我给你这个:

Delimiter //
Create Procedure addUser(
    IN facebookId varchar(20), 
        IN name varchar(50), 
        In accessToken varchar(100), 
        in expires float)
Begin
        Declare invitingUsers Table(Id varchar(20));
        
        Create temporary table if not exists invitingUsers
        (Id varchar(20), PRIMARY KEY (id)) ENGINE=MEMORY;

        Insert Into Users 
        (`Facebook_Id`,`Name`,`Access_Token`,`Expired`)
        Values (facebookId,name,accessToken,expires);

        INSERT INTO invitingUsers          
        Select Inviting_Id From Invited_Users
        Where Invited_Id = facebookId;
        
        Update Table Users 
        Set Credit = Credit + 1 
        Where Facebook_Id In (Select Id From invitingUsers);
End//
Delimiter ;

试试看 !!!

于 2013-07-16T18:32:46.833 回答