MySQL创建一个具有多个输入的函数

时间:2011-11-23 09:29:27

标签: mysql

我正在尝试使用多个输入创建一个MySQL函数,但不断出现错误:

DELIMITER $$
mysql> CREATE FUNCTION jb_test (a CHAR, b CHAR)
    -> RETURNS CHAR     
    -> DETERMINISTIC
    -> SET say = CONCAT(a,b);
    -> RETURN say;
    -> END$$
ERROR 1064 (42000): 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 'FUNCTION jb_test (a CHAR, b CHAR)
RETURNS CHAR
DETERMINISTIC
SET say = CONCAT(a,b' at line 1

2 个答案:

答案 0 :(得分:1)

CREATE FUNCTION jb_test (a CHAR, b CHAR)
  RETURNS CHAR
   DETERMINISTIC
    BEGIN
     DECLARE say CHAR;
     SET say = CONCAT(a,b);
     RETURN say;
    END|

答案 1 :(得分:0)

该功能的语法如下:

 mysql> CREATE FUNCTION function_name (s CHAR(20))
 mysql> RETURNS CHAR(50) DETERMINISTIC
  -> RETURN CONCAT('Hello, ',s,'!');

论证如下:

FUNCTION function_name (s CHAR(20))

FUNCTION sp_name ([func_parameter[,...]])

参考Mysql Documentation