修复mysql函数

时间:2015-05-22 10:55:33

标签: mysql

我正在尝试创建一个mysql函数。但它不起作用,以下是错误:

  

错误代码1064,SQL状态42000:您的SQL中有错误   句法;查看与MySQL服务器版本对应的手册   使用附近的正确语法   '=(CO,CO1,CO2,CO3,CO4,CO5,CO6,CO7,CO8,CO9,CO10,CO11,CO12,CO13,co14);'   在第58行

我试图修复但没有结果。

delimiter |
CREATE FUNCTION KPI15 (s VARCHAR(20000)) RETURNS VARCHAR(20000)
DETERMINISTIC
BEGIN

           DECLARE str  VARCHAR(2000);
           DECLARE toFind  VARCHAR(2000);
           DECLARE co VARCHAR(2000);
DECLARE co1 VARCHAR(2000);
DECLARE co2 VARCHAR(2000);
DECLARE co3 VARCHAR(2000);
DECLARE co4 VARCHAR(2000);
DECLARE co5 VARCHAR(2000);
DECLARE co6 VARCHAR(2000);
DECLARE co7 VARCHAR(2000);
DECLARE co8 VARCHAR(2000);
DECLARE co9 VARCHAR(2000);
DECLARE co10 VARCHAR(2000);
DECLARE co11 VARCHAR(2000);
DECLARE co12 VARCHAR(2000);
DECLARE co13 VARCHAR(2000);
DECLARE co14 VARCHAR(2000);
DECLARE cpt VARCHAR(21845);
           SET co='';
SET co1='';
SET co2='';
SET co3='';
SET co4='';
SET co5='';
SET co6='';
     SET co7='';
        SET co8='';
          SET co9='';
        SET co10='';
         SET co11='';
       SET co12='';
         SET co13='';
         SET co14='';
           SET cpt='';
           SET str='';
           SET toFind=s;

    SET str =SUBSTRING_INDEX(toFind,'sur',1);
        IF (str like ('%CDR%')) =1 THEN set co1 = 'CDR';
      ElSEIF (str like ('%DL DROP TBF%','%TBF FAIL%','%TBF DROP%','%TBF SR%','%DL TBF SR%','%UL FAIL TBF%','%DATA FAIL%','%FAIL TBF%','%DL DROP DATA%'))=1 THEN set co2 = 'FAIL ET DROP TBF';
         ElSEIF (str like ('%SD DROP%','%SDR%'))=1 THEN set co3 ='SDR';
        ElSEIF (str like ('%FAIL TCH%'))=1 THEN set co4 = 'FAIL TCH';
         ElSEIF (str like ('%HO LEVEL EN DL%','%HO QUALITE%','%HO INTERFERENCE%','%INC HO%'))=1 THEN set co5 = 'DEGRADATION HO';
          ElSEIF (str like ('%DEGRADATION DE TOUS LES KPI CS/PS%','%SLEEPING PS%','%SLEEPING CS%','%BAISSE DE TRAFFIC%'))=1 THEN set co6 = 'DEGRADATION DES KPI CS/PS 2G';
       ElSEIF (str like ('%CSSR%'))=1 THEN set co7 = 'CSSR';
        ElSEIF (str like ('%COUPURE BSS%','%CALL DROP BSS%','%DROP BSS%'))=1 THEN set co8 = 'CALL DROP BSS';
      ElSEIF (str like ('%HSPA DROP%','%HSPA RB DROP%','%HSPA Rb DROP%','%HSPA RAB SETUP%','%HSPA RAB SETUP SR%','%SLEEPING HSPA%','%HSPA SSR%','%HSPA SR%'))=1 THEN set co9 = 'HSPA';
           ElSEIF (str like ('%HSUPA RAB SETUP%','%SLEEPING HSUPA%'))=1 THEN set co10 = 'HSUPA';
          ElSEIF (str like ('%R99 DROP%','%R99 RB DROP%'))=1 THEN set co11 = 'R99';
       ElSEIF (str like ('%RRC SETUP SUCCESS OTHER RATE%','%RRC OTHER%','%RRC OTHERS%','%DEGRADATION RRC CS/PS SETUP%','%RRC SETUP SR%','%RRC SETUP SUCC SERV RATE%','%PS RRC SSR%','%PS RRC SETUP SR%'))=1 THEN set co12 = 'RRC';
         ElSEIF (str like ('%CS RAB%','%CS RAB SETUP%','%CS RAB SETUP SR%','%PS RAB DROP%','%PS RAB SETUP SR%'))=1 THEN set co13 = 'RAB';
         ElSEIF (str like ('%PS DROP%','%CS SERVICE DROP%'))=1 THEN set co14 = 'DEGRADATION DES KPI CS/PS 3G';
       ELSE SET co='vid';END IF;
           cpt=(co,co1,co2,co3,co4,co5,co6,co7,co8,co9,co10,co11,co12,co13,co14);
           return cpt;
              END |
           delimiter; 

1 个答案:

答案 0 :(得分:0)

你的函数声明说它返回VARCHAR。那条线应该是:

cpt=CONCAT(co,co1,co2,co3,co4,co5,co6,co7,co8,co9,co10,co11,co12,co13,co14);

或者如果你想要它们之间的分隔符:

cpt=CONCAT_WS(',', co,co1,co2,co3,co4,co5,co6,co7,co8,co9,co10,co11,co12,co13,co14);