解析特殊字符 - 函数Mysql 5.5?

时间:2016-03-09 16:32:08

标签: php mysql

我评论说我在尝试创建一个解析特殊字符的函数时遇到了问题,并以递归方式调用。

Mysql代码:

DROP FUNCTION IF EXISTS fn_obt_val_par_campo;
DELIMITER $$
CREATE FUNCTION fn_obt_val_par_campo(campo VARCHAR(80))
    RETURNS VARCHAR(80)
BEGIN

    DECLARE par_campo VARCHAR(80);
    DECLARE for_campo VARCHAR(80);
    DECLARE ind_campo INT DEFAULT 1;

    SET for_campo = LOWER(campo);

    WHILE ind_campo = 1 DO

        IF INSTR(for_campo, 'á') != 0 THEN
            SET par_campo = UPPER(REPLACE(for_campo, 'á', 'a'));
            SET for_campo = par_campo;
            SET ind_campo = 1;
        ELSEIF INSTR(for_campo, 'é') != 0 THEN
            SET par_campo = UPPER(REPLACE(for_campo, 'é', 'e'));
            SET ind_campo = 1;
        ELSEIF INSTR(for_campo, 'í') != 0 THEN
            SET par_campo = UPPER(REPLACE(for_campo, 'í', 'i'));
            SET ind_campo = 1;
        ELSEIF INSTR(for_campo, 'ó') != 0 THEN
            SET par_campo = UPPER(REPLACE(for_campo, 'ó', 'o'));
            SET ind_campo = 1;
        ELSEIF INSTR(for_campo, 'ú') != 0 THEN
            SET par_campo = UPPER(REPLACE(for_campo, 'ú', 'u'));
            SET ind_campo = 1;
        ELSE
            SET par_campo = UPPER(for_campo);
            SET ind_campo = 0;
        END IF;

    END WHILE;

    RETURN par_campo;

END;
$$
DELIMITER ;

咨询永远不会结束,连接被阻止mysql:

SELECT fn_obt_val_par_campo('ALVARZ') AS CAMPO

我希望你能解决我的问题。

1 个答案:

答案 0 :(得分:0)

这与特殊字符无关:

CREATE FUNCTION fn_obt_val_par_campo(campo VARCHAR(80))
    RETURNS VARCHAR(80);
                       ^---this is the error
BEGIN

在create / begin之间不允许使用分隔符,这就是全部。