Anakreon Mejdi wrote:
I am trying to create a stored function.
From the docs I saw the code for this function:
CREATE FUNCTION hello (s CHAR(20)) RETURNS CHAR(50)
DETERMINISTIC
RETURN CONCAT('Hello, ',s,'!');
The version from the docs did not contain the DETERMINISTIC keyword.
I added because it would not compile.
The problem is that if I change the code to:
CREATE FUNCTION hello (s CHAR(20)) RETURNS CHAR(50)
DETERMINISTIC
LANGUAGE SQL
BEGIN
RETURN CONCAT('Hello, ',s,'!');
END;
I get the error message:
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 'END'
at line 1
In this example you need to change the delimiter to something other than
; otherwise the MySQL client things that's the stopping point for a
statement and attempts to process.
mysql> delimiter //
mysql> CREATE FUNCTION hello (s CHAR(20)) RETURNS CHAR(50)
-> DETERMINISTIC
-> LANGUAGE SQL
-> BEGIN
-> RETURN CONCAT('Hello, ',s,'!');
-> END;
->
-> //
Query OK, 0 rows affected (0.01 sec)
mysql> delimiter ;
mysql> select hello("Mike");
+---------------+
| hello("Mike") |
+---------------+
| Hello, Mike! |
+---------------+
1 row in set (0.00 sec)
Hope that helps. Functions are covered pretty well in Pro MySQL
(Apress). I'm one of the authors.
--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe: http://lists.mysql.com/[EMAIL PROTECTED]