0

Can you please help me finding the error in the stored procedure? Thanks!!!

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;
4

2 回答 2

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 ;
于 2013-08-06T03:05:26.373 回答
0

DELIMITER //之前缺少分隔符定义CREATE PROCEDURE。还需要通过//在前面添加来终止程序,END如下所示:

DELIMITER // -- define your delimiter here
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 // -- terminate the procedure
DELIMITER ; -- revert to default delimiter
于 2021-11-03T11:31:06.347 回答