简体   繁体   English

创建功能时出现MySQL语法错误

[英]MySQL syntax error on FUNCTION creation

I've been trying to find my error for hours but nothing. 数小时以来,我一直在寻找错误,但一无所获。 So here is my function: 所以这是我的功能:

DELIMITER //
DROP FUNCTION IF EXISTS func_name//
CREATE FUNCTION func_name(_num_client INT) RETURNS VARCHAR(20)
BEGIN
DECLARE n_titul VARCHAR(20) DEFAULT NULL;
SET n_titul = (SELECT UPPER(
    IF(
        length(concat_ws(' ', civilite, prenom, nom)),
        IF(
            length(concat_ws(' ', civilite, concat(substring(prenom, 1, 1), '.'), nom)),
            substring(concat_ws(' ', civilite, concat(substring(prenom, 1, 1), '.'), nom), 1, 20),
            concat_ws(' ', civilite, concat(substring(prenom, 1, 1), '.'), nom)
        ),
        concat_ws(' ', civilite, prenom, nom)
    )
) FROM client WHERE num_client=_num_client) ;
RETURN n_titul;
END;
//

And I get this response : 我得到这个回应:

ERROR: Punctuation invalid @ 637 STR: // SQL: { HERE THE RESQUEST ABOVE }

#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 '//' at line 17

DELIMITER //
DROP FUNCTION IF EXISTS func_name//
CREATE FUNCTION func_name(_num_client INT) RETURNS VARCHAR(20)
BEGIN
DECLARE n_titul VARCHAR(20) DEFAULT NULL;
SET n_titul = (SELECT UPPER(
    IF(
        length(concat_ws(' ', civilite, prenom, nom)),
        IF(
            length(concat_ws(' ', civilite, concat(substring(prenom, 1, 1), '.'), nom)),
            substring(concat_ws(' ', civilite, concat(substring(prenom, 1, 1), '.'), nom), 1, 20),
            concat_ws(' ', civilite, concat(substring(prenom, 1, 1), '.'), nom)
        ),
        concat_ws(' ', civilite, prenom, nom)
    )
) FROM client WHERE num_client=_num_client) ;
RETURN n_titul;
END//
DELIMITER ;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM