开发者

MySQL: failed to create function {functionName}

开发者 https://www.devze.com 2023-01-03 18:45 出处:网络
This works on MySQL 5.0.41, but on 5.1.31 it just says \"failed to create function\". I type this in the console:

This works on MySQL 5.0.41, but on 5.1.31 it just says "failed to create function". I type this in the console:

delimiter |
<press enter>
CREATE DEFINER=`root`@`localhost` FUNCTION `ucwords`( str VARCHAR(128) ) RETURNS varchar(128) CHARSET utf8
BEGIN
  DECLARE c CHAR(1);
  DECLARE s VARCHAR(128);
  DECLARE i INT DEFAULT 1;
  DECLARE bool INT DEFAULT 1;
  DECLARE punct CHAR(17) DEFAULT ' ()[]{},.-_!@;:?/';
  SET s = LCASE( str );
  WHILE i < LENGTH( str ) DO 
    BEGIN
      SET c = SUBSTRING( s, i, 1 );
      IF LOCATE( c, punct ) > 0 THEN
        SET bool = 1;
      ELSEIF bool=1 THEN 
        BEGIN
          IF c >= 'a' AND c <= 'z' THEN 
            BEGIN
              SET s = CONCAT(LEFT(s,i-1),UCASE(c),SUBSTRING(s,i+1));
              SET bool = 0;
            END;
          ELSEIF c >= '0' AND c <= '9' THEN
            SET bool = 0;
          END IF;
        END;
      END IF;
      SET i = i+1;
    END;
  END WHILE;
  RETURN s;
END |
<press enter>

I have even tried minimizing it to just:

delimiter |
<press enter>
CREATE DEFINER=`root`@`localhost` FUNCTION `ucwords`( str VARCHAR(128) ) RETURNS varchar(128) CHARSET utf8
BEGIN
  DECLARE s VARCHAR(128);
  RETURN s;
END |
<press enter>

I have even tried it without the definer, just using:

delimiter |
<press enter>
CREATE FUNCTION `ucwords`( str VARCHAR(128) ) RETURNS varchar(128) CHARSET utf8
BEGIN
  DECLARE开发者_如何学JAVA s VARCHAR(128);
  RETURN s;
END |
<press enter>


Did you recently upgrade from MySQL 5.0 to 5.1? If so, you need to run the mysql_upgrade script to update the system tables. In this case, the mysql.proc table schema changed, which could explain your problem: http://dev.mysql.com/doc/refman/5.1/en/mysql-upgrade.html

More on upgrading to 5.1: http://dev.mysql.com/doc/refman/5.1/en/upgrading-from-previous-series.html

0

精彩评论

暂无评论...
验证码 换一张
取 消