mysql delimiter error

后端 未结 8 1621
别那么骄傲
别那么骄傲 2020-12-06 16:53

Modifed.

DROP FUNCTION IF EXISTS PersonName;
DELIMITER |;

CREATE FUNCTION PersonName( personID SMALLINT )
RETURNS CHAR(20)
BEGIN
  DECLARE pname CHAR         


        
相关标签:
8条回答
  • 2020-12-06 17:32

    I would remove the semicolon after END.

        ...
    END
    |
    DELIMITER ;
    

    Re your comment, you can't use the current delimiter when declaring a new delimiter. That sounds confusing, but consider if you do this:

    DELIMITER |;
    

    Now MySQL would think the delimiter is "|;" (two characters, a pipe and a semicolon). If you think about it, DELIMITER must be treated in a special way by the MySQL client. It's the only statement that can't be followed by the current delimiter.

    So when setting the delimiter to pipe, do this:

    DELIMITER |
    

    When setting it back to semicolon, do this:

    DELIMITER ;
    

    FWIW, I ran the following with no error on my local test database on MySQL 5.0.75:

    DROP FUNCTION IF EXISTS PersonName;
    DELIMITER |
    
    CREATE FUNCTION PersonName( personID SMALLINT )
    RETURNS CHAR(20)
    BEGIN
      DECLARE pname CHAR(20) DEFAULT '';
      SELECT name INTO pname FROM family WHERE ID=personID;
      RETURN pname;
    END
    |
    DELIMITER ;
    
    0 讨论(0)
  • 2020-12-06 17:36

    In your last line where you're restoring the delimiter to semicolon you need a space between DELIMITER and ; i.e.

    DELIMITER ;
    
    0 讨论(0)
提交回复
热议问题