我尝试运行以下代码:
std.execute(" DELIMITER $$" +
" CREATE FUNCTION findfood ( col VARCHAR , inp VARCHAR , c_length INT , i_length INT ) " +
" RETURNS VARCHAR" +
" BEGIN " +
" DECLARE i INT;" +
" SET i = 0;" +
" DECLARE co INT;" +
" SET co = 0;" +
" DECLARE out VARCHAR;" +
" DECLARE out_match VARCHAR;" +
" lp: LOOP" +
" IF CAST(SUBSTRING_INDEX(col,'-',1) AS UNSIGNED) > CAST(SUBSTRING_INDEX(inp,'-',1) AS UNSIGNED) THEN" +
" SET i = i+1;" +
" SET inp = SUBSTRING_INDEX(inp,'-',i - i_length);" +
" ELSEIF CAST(SUBSTRING_INDEX(col,'-',1) AS UNSIGNED) < CAST(SUBSTRING_INDEX(inp,'-',1) AS UNSIGNED) THEN" +
" SET out = CONCAT(out,'-',SUBSTRING_INDEX(col,'-',1));" +
" SET co = co+1;" +
" SET col = SUBSTRING_INDEX(col,'-',co - c_length);"+
" ELSE" +
" SET out_match = CONCAT(out_match,'-',SUBSTRING_INDEX(col,'-',1));" +
" SET co = co+1;" +
" SET col = SUBSTRING_INDEX(col,'-',co - c_length); " +
" SET i = i+1;" +
" SET inp = SUBSTRING_INDEX(inp,'-',i - i_length);" +
" END IF;" +
" IF i = i_length THEN" +
" IF co = c_length THEN" +
" LEAVE lp;" +
" ELSE" +
" SET out = CONCAT(out,col);" +
" LEAVE lp;" +
" END IF;" +
" ELSE " +
" IF co = c_length THEN" +
" LEAVE lp;" +
" ELSE" +
" ITERATE lp;" +
" END IF;" +
" END IF;" +
" END LOOP lp;" +
" SET out = CONCAT(SUBSTRING_INDEX(out_match,'-',1),'_',SUBSTRING_INDEX(out,'-',1));" +
" RETURN out;" +
"END $$" +
"DELIMITER ;");
++++++++++++++++++++++++++++++++++++++++++++++ < / p>
但是我收到了这个错误:
java.sql.SQLSyntaxErrorException :( conn:115)您的SQL语法中有错误;查看与MariaDB服务器版本对应的手册,以便在'DELIMITER $$ CREATE FUNCTION findfood附近使用正确的语法(col TEXT,inp TEXT,c_length INT,i_l'在第1行
++++++++++++++++++++++++++++++++++++++++++++++ < / p>