2013-08-05 81 views
0

你能幫我找到存儲過程中的錯誤嗎?謝謝!!!無法修復存儲過程錯誤

 
CREATE PROCEDURE 
     realiza_tracking_primer_lectura (
     in v_campaign_id int(11), 
     in v_ares_emails_id int(11), 
     in v_userid int(11), 
     in v_country varchar(2), 
     in v_ip varchar(15), 
     in v_useragent varchar(255), 
     in v_time int(11)) 
     BEGIN 
     DECLARE ReadBefore int DEFAULT null; 
     if v_campaign_id is Null then 
      SELECT userid FROM tracking_lecturas WHERE ares_emails_id = v_ares_emails_id and userid = v_userid into ReadBefore; 
     Else 
      SELECT userid FROM tracking_lecturas WHERE campaign_id = v_campaign_id and userid = v_userid into ReadBefore; 
     end if; 

     if ReadBefore is Null then 
      insert into tracking_lecturas (campaign_id, ares_emails_id, userid, ip, useragent, timestamp) values (v_campaign_id, v_ares_emails_id, v_userid, v_ip, v_useragent, v_time); 
     end if; 

     END 
     DELIMITER; 
+2

請分享你得到的錯誤 - 沒有編制?編譯但運行時錯誤?運行但結果不正確? –

+0

運行或編譯時出錯? –

回答

0

試試這個:

-- Dumping structure for procedure test.realiza_tracking_primer_lectura 
DROP PROCEDURE IF EXISTS `realiza_tracking_primer_lectura`; 
DELIMITER // 
CREATE PROCEDURE `realiza_tracking_primer_lectura`(IN `v_campaign_id` int(11),IN `v_ares_emails_id` int(11),IN `v_userid` int(11),IN `v_country` varchar(2),IN `v_ip` varchar(15),IN `v_useragent` varchar(255),IN `v_time` int(11)) 
BEGIN 
    #Routine body goes here... 
     DECLARE ReadBefore int DEFAULT null; 
     if v_campaign_id is Null then 
      SELECT userid FROM tracking_lecturas WHERE ares_emails_id = v_ares_emails_id and userid = v_userid into ReadBefore; 
     Else 
      SELECT userid FROM tracking_lecturas WHERE campaign_id = v_campaign_id and userid = v_userid into ReadBefore; 
     end if; 

     if ReadBefore is Null then 
      insert into tracking_lecturas (campaign_id, ares_emails_id, userid, ip, useragent, timestamp) values (v_campaign_id, v_ares_emails_id, v_userid, v_ip, v_useragent, v_time); 
     end if; 

END// 
DELIMITER ;