joedborg
joedborg

Reputation: 18353

MySQL create a function with mulitple inputs

I'm trying to create a MySQL function with multiple inputs, but keep getting an error:

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

Upvotes: 0

Views: 819

Answers (2)

Dirk De Winnaar
Dirk De Winnaar

Reputation: 167

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

Upvotes: 1

Mithun Sasidharan
Mithun Sasidharan

Reputation: 20920

The syntax for the function is as follows:

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

The argument is as given below

FUNCTION function_name (s CHAR(20))

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

Refer Mysql Documentation

Upvotes: 0

Related Questions