0
CREATE FUNCTION testing(id INT, dsc TEXT) RETURNS TEXT
BEGIN
DECLARE ntxt TEXT;
SET ntxt = dsc;
RETURNS ntxt;
END;

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 'TEXT' at line 3

What i miss here ?

2 Answers 2

1
  1. You forgot to change the delimiter
  2. RETURN has an extra S

This does work:

DELIMITER //

CREATE FUNCTION testing(id INT, dsc TEXT) RETURNS TEXT
BEGIN
    DECLARE ntxt TEXT;
    SET ntxt = dsc;
    RETURN ntxt;
END//
Sign up to request clarification or add additional context in comments.

1 Comment

DELIMITER was the problem. Thanks
0

You probably forgot to add DELIMITER $$ in the very beginning of your script (Standard delimiter is ;, and it's also used in procedures/functions). For example,

 DELIMITER $$
 [CREATE FUNCTION ...... ]
 $$
 DELIMITER ;

3 Comments

why are coders obsessed with the $$ when a single non ; will do - like a # ?
@f00, I guess you feel better when the alternative delimiter is not likely to appear anywhere else.
+1. Just for example :) Surely, it can be anything. Personally I prefer //. But it seems $$ to be more "common"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.