0

我有一个引发错误的存储过程。

这是电话:

CALLcampaign_strat_placement_test ('10541','2013-1-1','2013-1-7',2,0, 2 ,0,0,32)

我已将导致错误的部分加粗,因为如果我将该选项更改为 0 或 1,程序就会运行。

这是整个过程:

    DELIMITER $$

    USE `reporting`$$

    DROP PROCEDURE IF EXISTS `campaign_strat_placement_test`$$

    CREATE DEFINER=`username`@`%` PROCEDURE `campaign_strat_placement_test`(strat_id VARCHAR(255),rpt_start_date DATE, rpt_end_date DATE,mrt_opt INT, mrt_rev_opt INT, mro_opt INT, mro_rev_opt INT, media_cost_opt INT, metrics_opt INT)
COMMENT 'returns client report'
    BEGIN
SELECT report_title FROM reporting.campaign_meta_cron_daily WHERE strategy_id = strat_id;
SELECT CONCAT('Data Updated Through ',DATE_FORMAT(ADDDATE(CURDATE(),-1),'%M %d, %Y'));    

SET @report_code:=CONCAT('
    select date(date) as `Date`
    , placement_id
    , placement_name
    , strategy_name as strategy
    , concept
    , size
    , exchange
    , targeting_strat
    , ifnull(IMPS_3P,0) as Imps
    , ifnull(CLICKS_3P,0) as Clicks
    ',CASE WHEN mrt_opt = 1 THEN
        ' ,ifnull(MRT_PC_3P,0) as MRT_PC'
        WHEN mrt_opt = 2 THEN 
        ' ,ifnull(MRT_PC_3P,0) as MRT_PC
        ,ifnull(MRT_PV_3P*goal1_pv_discount,0) as MRT_PV'
        WHEN mrt_opt = 3 THEN 
        ' ,ifnull(MRT_PC_3P+(MRT_PV_3P*goal1_pv_discount),0) as MRT_Tot'
        ELSE '' END
    ,CASE WHEN mrt_rev_opt = 1 THEN
        ' ,ifnull(round(sum(MRT_PC_REV_3P),2),0) as MRT_PC_Rev'
        WHEN mrt_rev_opt = 2 THEN 
        ' ,ifnull(MRT_PC_REV_3P,0) as MRT_PC_Rev
        ,ifnull(MRT_PV_REV_3P*goal1_pv_discount,0) as MRT_PV_Rev'
        WHEN mrt_rev_opt = 3 THEN 
        ' ,ifnull(MRT_PC_REV_3P+(MRT_PV_REV_3P*goal1_pv_discount),0) as MRT_Rev'
        ELSE '' END
    ,CASE WHEN mro_opt = 1 THEN
        ' ,ifnull(MRO_PC_3P,0) as MRO_PC'
        WHEN mro_opt = 2 THEN 
        ' ,ifnull(MRO_PC_3P,0) as MRO_PC
        ,ifnull(MRO_PV_3P*goal1_pv_discount,0) as MRO_PV'
        WHEN mro_opt = 3 THEN 
        ' ,ifnull((MRO_PC_3P+(MRO_PV_3P*goal1_pv_discount)),0) as MRO_Tot'
        ELSE '' END
    ,CASE WHEN mro_rev_opt = 1 THEN
        ' ,ifnull(round(MRO_PC_REV_3P,2),0) as MRO_PC_Rev'
        WHEN mro_rev_opt = 2 THEN 
        ' ,ifnull(round(MRO_PC_REV_3P,2),0) as MRO_PC_Rev
        ,ifnull(round(MRO_PV_REV_3P,2),0) as MRO_PV_Rev'
        WHEN mro_rev_opt = 3 THEN 
        ' ,ifnull(round(MRO_PC_REV_3P+sum(MRO_PV_REV_3P*goal1_pv_discount),2),0) as MRO_Rev'
        ELSE '' END
    ,CASE WHEN media_cost_opt = 1 THEN
        ' ,ifnull(round(gross_media_cost,2),0) as Media_Cost'
        WHEN media_cost_opt = 2 THEN 
        ' ,ifnull(round(net_media_cost,2),0) as Net_Media_Cost
         ,ifnull(round(gross_media_cost,2),0) as Gross_Media_Cost'
        ELSE ' ,ifnull(round(net_media_cost,2),0) as Media_Cost' END
    ,CASE WHEN metrics_opt%2 >= 1 THEN 
        ' ,round(ifnull(CLICKS_3P/IMPS_3P,0),4) as CTR' ELSE '' END
    ,CASE WHEN metrics_opt%4 >= 2 THEN 
        ' ,round(ifnull((MRT_PC_3P+(sum(MRT_PV_3P)*goal1_pv_discount))/IMPS_3P*1000,0),4) as RR_per_M' ELSE '' END
    ,CASE WHEN metrics_opt%8 >= 4 THEN 
        ' ,round(ifnull((net_media_cost/IMPS_3P)*1000,0),2) as Net_CPM' ELSE '' END
    ,CASE WHEN metrics_opt%16 >= 8 THEN 
        ' ,round(ifnull(net_media_cost/CLICKS_3P,0),2) as Net_CPC' ELSE '' END
    ,CASE WHEN metrics_opt%32 >= 16 THEN 
        ' ,round(ifnull(net_media_cost/(MRT_PC_3P+(MRT_PV_3P*goal1_pv_discount)),0),2) as Net_CPA' ELSE '' END
    ,CASE WHEN metrics_opt%64 >= 32 THEN 
        ' ,round(ifnull((gross_media_cost/IMPS_3P)*1000,0),2) as Gross_CPM' ELSE '' END
    ,CASE WHEN metrics_opt%128 >= 64 THEN 
        ' ,round(ifnull(gross_media_cost/CLICKS_3P,0),2) as Gross_CPC' ELSE '' END
    ,CASE WHEN metrics_opt%256 >= 128 THEN 
        ' ,round(ifnull(gross_media_cost/(MRT_PC_3P+(MRT_PV_3P*goal1_pv_discount)),0),2) as Gross_CPA' ELSE '' END
    ,CASE WHEN metrics_opt%512 >= 256 THEN 
        ' ,round(ifnull(((MRT_PC_REV_3P+(MRT_PV_REV_3P*goal1_pv_discount))/net_media_cost)-1,0),2) as Net_ROI' ELSE '' END
    ,CASE WHEN metrics_opt%1024 >= 512 THEN 
        ' ,round(ifnull(((MRT_PC_REV_3P+(MRT_PV_REV_3P*goal1_pv_discount))/gross_media_cost)-1,0),2) as Gross_ROI' ELSE '' END
    ,CASE WHEN metrics_opt%2048 >= 1024 THEN 
        ' ,round(ifnull(net_media_cost/(MRT_PC_3P+(MRT_PV_3P*goal1_pv_discount)),0),2) as Alt_Net_CPA' ELSE '' END
    ,CASE WHEN metrics_opt%4096 >= 2048 THEN 
        ' ,round(ifnull(gross_media_cost/(MRT_PC_3P+(MRT_PV_3P*goal1_pv_discount)),0),2) as Alt_Gross_CPA' ELSE '' END
    ,CASE WHEN metrics_opt%8192 >= 4096 THEN 
        ' ,round(ifnull(((MRO_PC_REV_3P+(MRO_PV_REV_3P*goal1_pv_discount))/net_media_cost)-1,0),2) as Alt_Net_ROI' ELSE '' END
    ,CASE WHEN metrics_opt%16384 >= 8192 THEN 
        ' ,round(ifnull(((MRO_PC_REV_3P+(MRO_PV_REV_3P*goal1_pv_discount))/gross_media_cost)-1,0),2) as Alt_Gross_ROI' ELSE '' END
    ,CASE WHEN metrics_opt%32768 >= 16384 THEN 
        ' ,round(ifnull((MRO_PC_3P+(sum(MRO_PV_3P)*goal1_pv_discount))/IMPS_3P*1000,0),4) as Alt_RR_per_M' ELSE '' END
,' from external_02.creative
where strategy_id in (',strat_id,')
    and date >= ''',rpt_start_date,'''
and date <= ''',rpt_end_date,'''
group by date(date) 
    ,advsym
    ,strategy_name
    ,placement_id
    ,placement_name
    ,concept
    ,size
    ,exchange
    ,targeting_strat
UNION ALL 
select ''Total'' as `Date`
    , '''' as placement_id
    , '''' as placement_name
    , '''' as strategy
    , '''' as concept
    , '''' as size
    , '''' as exchange
    , '''' as targeting_strat
    , ifnull(sum(IMPS_3P),0) as Imps
    , ifnull(sum(CLICKS_3P),0) as Clicks
    ',CASE WHEN mrt_opt = 1 THEN
        ' ,ifnull(sum(MRT_PC_3P),0) as MRT_PC'
        WHEN mrt_opt = 2 THEN 
        ' ,ifnull(sum(MRT_PC_3P),0) as MRT_PC
        ,ifnull(sum(MRT_PV_3P*goal1_pv_discount),0) as MRT_PV'
        WHEN mrt_opt = 3 THEN 
        ' ,ifnull(sum(MRT_PC_3P)+sum(MRT_PV_3P*goal1_pv_discount),0) as MRT_Tot'
        ELSE '' END
    ,CASE WHEN mrt_rev_opt = 1 THEN
        ' ,ifnull(sum(MRT_PC_REV_3P),0) as MRT_PC_Rev'
        WHEN mrt_rev_opt = 2 THEN 
        ' ,ifnull(sum(MRT_PC_REV_3P),0) as MRT_PC_Rev
        ,ifnull(sum(MRT_PV_REV_3P*goal1_pv_discount),0) as MRT_PV_Rev'
        WHEN mrt_rev_opt = 3 THEN 
        ' ,ifnull(sum(MRT_PC_REV_3P)+sum(MRT_PV_REV_3P*goal1_pv_discount),0) as MRT_Rev'
        ELSE '' END
    ,CASE WHEN mro_opt = 1 THEN
        ' ,ifnull(sum(MRO_PC_3P),0) as MRO_PC'
        WHEN mro_opt = 2 THEN 
        ' ,ifnull(sum(MRO_PC_3P),0),0) as MRO_PC
        ,ifnull(sum(MRO_PV_3P*goal1_pv_discount),0) as MRO_PV'
        WHEN mro_opt = 3 THEN 
        ' ,ifnull(sum(MRO_PC_3P)+sum(MRO_PV_3P*goal1_pv_discount),0) as MRO_Tot'
        ELSE '' END
    ,CASE WHEN mro_rev_opt = 1 THEN
        ' ,ifnull(round(sum(MRO_PC_REV_3P),2),0) as MRO_PC_Rev'
        WHEN mro_rev_opt = 2 THEN 
        ' ,ifnull(sum(MRO_PC_REV_3P),0) as MRO_PC_Rev
        ,ifnull(sum(MRO_PV_REV_3P*goal1_pv_discount),0) as MRO_PV_Rev'
        WHEN mro_rev_opt = 3 THEN 
        ' ,ifnull(round(sum(MRO_PC_REV_3P)+sum(MRO_PV_REV_3P*goal1_pv_discount),2),0) as MRO_Rev'
        ELSE '' END
    ,CASE WHEN media_cost_opt = 1 THEN
        ' ,ifnull(round(sum(gross_media_cost),2),0) as Media_Cost'
        WHEN media_cost_opt = 2 THEN 
        ' ,ifnull(round(sum(net_media_cost),2),0) as Net_Media_Cost
         ,ifnull(round(sum(gross_media_cost),2),0) as Gross_Media_Cost'
        ELSE ' ,ifnull(round(sum(net_media_cost),2),0) as Media_Cost' END
    ,CASE WHEN metrics_opt%2 >= 1 THEN 
        ' ,round(ifnull(sum(CLICKS_3P)/sum(IMPS_3P),0),4) as CTR' ELSE '' END
    ,CASE WHEN metrics_opt%4 >= 2 THEN 
        ' ,round(ifnull((sum(MRT_PC_3P)+(sum(MRT_PV_3P)*goal1_pv_discount))/sum(IMPS_3P)*1000,0),4) as RR_per_M' ELSE '' END
    ,CASE WHEN metrics_opt%8 >= 4 THEN 
        ' ,round(ifnull((sum(net_media_cost)/sum(IMPS_3P))*1000,0),2) as Net_CPM' ELSE '' END
    ,CASE WHEN metrics_opt%16 >= 8 THEN 
        ' ,round(ifnull(sum(net_media_cost)/sum(CLICKS_3P),0),2) as Net_CPC' ELSE '' END
    ,CASE WHEN metrics_opt%32 >= 16 THEN 
        ' ,round(ifnull((sum(net_media_cost))/((sum(MRT_PC_3P))+(sum(MRT_PV_3P)*goal1_pv_discount)),0),2) as Net_CPA' ELSE '' END
    ,CASE WHEN metrics_opt%64 >= 32 THEN 
        ' ,round(ifnull((sum(gross_media_cost)/sum(IMPS_3P))*1000,0),2) as Gross_CPM' ELSE '' END
    ,CASE WHEN metrics_opt%128 >= 64 THEN 
        ' ,round(ifnull(sum(gross_media_cost)/sum(CLICKS_3P),0),2) as Gross_CPC' ELSE '' END
    ,CASE WHEN metrics_opt%256 >= 128 THEN 
        ' ,round(ifnull((sum(gross_media_cost))/((sum(MRT_PC_3P))+(sum(MRT_PV_3P)*goal1_pv_discount)),0),2) as Gross_CPA' ELSE '' END
    ,CASE WHEN metrics_opt%512 >= 256 THEN 
        ' ,round(ifnull(((sum(MRT_PC_REV_3P)+(sum(MRT_PV_REV_3P)*goal1_pv_discount))/sum(net_media_cost))-1,0),2) as Net_ROI' ELSE '' END
    ,CASE WHEN metrics_opt%1024 >= 512 THEN 
        ' ,round(ifnull(((sum(MRT_PC_REV_3P)+(sum(MRT_PV_REV_3P)*goal1_pv_discount))/sum(gross_media_cost))-1,0),2) as Gross_ROI' ELSE '' END
    ,CASE WHEN metrics_opt%2048 >= 1024 THEN 
        ' ,round(ifnull((sum(net_media_cost))/((sum(MRT_PC_3P))+(sum(MRT_PV_3P)*goal1_pv_discount)),0),2) as Alt_Net_CPA' ELSE '' END
    ,CASE WHEN metrics_opt%4096 >= 2048 THEN 
        ' ,round(ifnull((sum(gross_media_cost))/((sum(MRT_PC_3P))+(sum(MRT_PV_3P)*goal1_pv_discount)),0),2) as Alt_Gross_CPA' ELSE '' END
    ,CASE WHEN metrics_opt%8192 >= 4096 THEN 
        ' ,round(ifnull(((sum(MRO_PC_REV_3P)+(sum(MRO_PV_REV_3P)*goal1_pv_discount))/sum(net_media_cost))-1,0),2) as Alt_Net_ROI' ELSE '' END
    ,CASE WHEN metrics_opt%16384 >= 8192 THEN 
        ' ,round(ifnull(((sum(MRO_PC_REV_3P)+(sum(MRO_PV_REV_3P)*goal1_pv_discount))/sum(gross_media_cost))-1,0),2) as Alt_Gross_ROI' ELSE '' END
    ,CASE WHEN metrics_opt%32768 >= 16384 THEN 
        ' ,round(ifnull((sum(MRO_PC_3P)+(sum(MRO_PV_3P)*goal1_pv_discount))/sum(IMPS_3P)*1000,0),4) as Alt_RR_per_M' ELSE '' END
,' from external_02.creative
where strategy_id in (',strat_id,')
and date >= ''',rpt_start_date,'''
and date <= ''',rpt_end_date,''';');



# Prepares and executes the dynamic SQL statement.
PREPARE ExecStatement FROM @report_code;
EXECUTE ExecStatement;
# Deallocates statement.
DEALLOCATE PREPARE ExecStatement;
# Prepares and executes the dynamic SQL statement.
END$$

    DELIMITER ;

这是我得到的错误:

    Error Code: 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 ') as MRO_PC
,ifnull(sum(MRO_PV_3P*goal1_pv_discount),0) as MRO_PV ,ifnull(rou' at line 38

这很令人困惑,因为我在第 38 行找不到该代码......

该错误似乎围绕代码的WHEN mrt_opt = 2 THEN部分。因为(正如我之前所说)如果该选项为 0 或 1,则该过程有效。

我花了很长时间看这个,想要一双新鲜的眼睛。

谢谢!

4

1 回答 1

0

,0)在关于该代码的声明中有一个额外的内容。

搜索并更改以下行:

WHEN mro_opt = 2 THEN 
    ' ,ifnull(sum(MRO_PC_3P),0),0) as MRO_PC

对此:

WHEN mro_opt = 2 THEN 
    ' ,ifnull(sum(MRO_PC_3P),0) as MRO_PC
于 2013-01-09T17:56:11.267 回答