2011-03-10 75 views
0

我寫了一個存儲過程,在我的本地機器上工作,但在服務器中,它不會執行!這將是有很大的幫助存儲過程在本地工作,但不會在服務器上執行

存儲過程是

 
DROP PROCEDURE `ASKUS_INSERT`// 
CREATE DEFINER=`root`@`localhost` PROCEDURE `ASKUS_INSERT`(
SENDERCONSUMERID INT(11), 
QUESTION_POSTED TEXT, 
DESCRIPTION_POSTED TEXT, 
NETWORK_ID INT(11), 
COMMTYPEID INT(11), 
CONSUMERID INT(11), 
CATEGORY_ID INT(11), 
ACTIONID INT(11), 
QUESTION_SLUG TEXT 
) 
BEGIN 
    DECLARE LASTINSERTEDID INT DEFAULT 0; 
    DECLARE GETTIPSAMOUNT INT DEFAULT 0; 
    DECLARE GETTIPSAMOUNTCONSUMER INT DEFAULT 0; 
    DECLARE SETTIPSAMOUNTCONSUMER INT DEFAULT 0; 
    DECLARE CHECKCOUNTTIPSEXIST INT DEFAULT 0; 

    SELECT COUNT(*) INTO CHECKCOUNTTIPSEXIST FROM ACTION_ENTERPRISE_MAPPING WHERE ACTION_ID = ACTIONID; 
    IF CHECKCOUNTTIPSEXIST > 0 THEN 
     SELECT SUM(TIP_AMOUNT) INTO GETTIPSAMOUNT FROM ACTION_ENTERPRISE_MAPPING WHERE ACTION_ID = ACTIONID; 
    ELSE 
     SET GETTIPSAMOUNT = 0; 
    END IF;  


    SELECT CONSUMER_TIPS INTO GETTIPSAMOUNTCONSUMER FROM CONSUMER_PROFILE WHERE CONSUMER_ID = SENDERCONSUMERID; 
    SET SETTIPSAMOUNTCONSUMER = GETTIPSAMOUNTCONSUMER + GETTIPSAMOUNT; 


    INSERT INTO NETWORK_COMMUNICATIONS (COMMUNICATIONS_ID,SENDER_CONSUMER_ID,NETWORK_COMM_TYPE_ID,PARENT_COMMUNICATIONS_ID,IS_ACTIVE,LAST_MOD_TIME,CONSUMER_ID) VALUES ('',SENDERCONSUMERID,COMMTYPEID,'0','1',NOW(),CONSUMERID); 

    SET LASTINSERTEDID = LAST_INSERT_ID(); 

    UPDATE CONSUMER_PROFILE SET CONSUMER_TIPS = SETTIPSAMOUNTCONSUMER WHERE CONSUMER_ID = SENDERCONSUMERID; 
    INSERT INTO CONSUMER_ACTION_LOG (ACTION_LOG_ID,ACTION_ID,CONSUMER_ID,TIPS_AMOUNT,LAST_MOD_TIME,COMMUNICATIONS_ID,COMM_TYPE_ID) VALUES ('',ACTIONID,SENDERCONSUMERID,GETTIPSAMOUNT,NOW(),LASTINSERTEDID,ACTIONID);  


    INSERT INTO NETWORK_COMMUNICATIONS_MESSAGE (NETWORK_COMMUNICATION_MESSAGE_ID,COMMUNICATIONS_ID,SUBJECT,MESSAGE,IS_ACTIVE,LAST_MOD_TIME,QUESTION_SLUG) VALUES ('',LASTINSERTEDID,QUESTION_POSTED,DESCRIPTION_POSTED,'1',NOW(),QUESTION_SLUG); 


    INSERT INTO COMMUNICATION_INTEREST_MAPPING (ID,CONSUMER_INTEREST_EXPERT_ID,CONSUMER_ID,COMMUNICATION_ID,IN_NETWORK,LAST_MOD_TIME) VALUES ('',CATEGORY_ID,SENDERCONSUMERID,LASTINSERTEDID,NETWORK_ID,NOW());  

    IF SENDERCONSUMERID != 0 AND CONSUMERID != 0 AND SENDERCONSUMERID != CONSUMERID THEN 
    INSERT INTO CONSUMER_NOTIFICATION (CONSUMER_NOTIFICATION_ID,CONSUMER_ID,SENDER_CONSUMER_ID,ACTION_ID,COMMUNICATIONS_ID,IS_ACTIVE,LAST_MOD_TIME) VALUES ('',CONSUMERID,SENDERCONSUMERID,COMMTYPEID,LASTINSERTEDID,'1',NOW()); 
    END IF; 
END 

它說有很多語法錯誤,也未知變量。在這種情況下,它不應該在我的本地主機上工作。但它確實!我很困惑!

回答

2

如果這樣工作,你不應該改變分隔符嗎?現在你中途有;可能會造成麻煩?

您可以看起來像這樣的例子檢查出this manual page

mysql> delimiter // 

mysql> CREATE PROCEDURE simpleproc (OUT param1 INT) 
    -> BEGIN 
    -> SELECT COUNT(*) INTO param1 FROM t; 
    -> END// 
Query OK, 0 rows affected (0.00 sec) 

mysql> delimiter ; 

正如你所看到的,分隔符首先設置爲「//」。你的第一行意味着你正在嘗試做那樣的事情。也許你只是忘了粘貼分隔線?

這樣的:

DROP PROCEDURE `ASKUS_INSERT`// 

只設定在 '//' 分隔符的工作。你應該(看例子)也可以以//結尾。

+0

所以我應該儘量把所有的「;」 ? – batty

+0

不,請查看本手冊頁面:http://dev.mysql.com/doc/refman/5.0/en/create-procedure.html:您可以將分隔符設置爲其他內容,然後添加您的過程,然後設置它背部。 – Nanne

相關問題