我有一个语法错误,我一直在努力修复,但我无法弄明白。错误告诉
附近有问题'SET result = CONCAT(result,charac); END IF; SET indexchar = indexchar+1;'
我正在尝试创建的全部功能:
DELIMITER //
DROP FUNCTION IF EXISTS `alphabet`;
CREATE FUNCTION `alphabet` (serial_number CHAR, name VARCHAR(100)) RETURNS VARCHAR(50)
DETERMINISTIC
BEGIN
DECLARE result VARCHAR(40) DEFAULT '';
DECLARE stringalpha VARCHAR(50) DEFAULT 'abcdefghijklmnopqrstuvwxyz0123456789';
DECLARE indexchar int DEFAULT 1;
DECLARE charlength INT;
DECLARE charac CHAR(1);
SET charlength = CHAR_LENGTH(stringalpha);
WHILE indexchar <= charlength DO
SET charac = SUBSTRING(stringalpha,indexchar,1);
IF (serial_number LIKE CONCAT('%',charac,'%') OR name LIKE CONCAT('%',charac,'%'))
SET result = CONCAT(result,charac);
END IF;
SET indexchar = indexchar+1;
END WHILE
RETURN result;
END //
DELIMITER ;
我试图写不成功:
SET result = CONCAT('result','charac');
答案 0 :(得分:1)
DROP FUNCTION IF EXISTS `alphabet`;
DELIMITER //
CREATE FUNCTION `alphabet` (serial_number CHAR, name VARCHAR(100)) RETURNS VARCHAR(50)
DETERMINISTIC
BEGIN
DECLARE result VARCHAR(40) DEFAULT '';
DECLARE stringalpha VARCHAR(50) DEFAULT 'abcdefghijklmnopqrstuvwxyz0123456789';
DECLARE indexchar int DEFAULT 1;
DECLARE charlength INT;
DECLARE charac CHAR(1);
SET charlength = CHAR_LENGTH(stringalpha);
WHILE indexchar <= charlength DO
SET charac = SUBSTRING(stringalpha,indexchar,1);
IF (serial_number LIKE CONCAT('%',charac,'%') OR name LIKE CONCAT('%',charac,'%')) THEN
SET result = CONCAT(result,charac);
END IF;
SET indexchar = indexchar+1;
END WHILE; -- ********************** missing semi
RETURN result;
END //
DELIMITER ;
缺少THEN
,END WHILE
后缺少分号,顶部的分隔符位于错误的行