Nick
Nick

Reputation: 16105

Problem with user defined function

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 ?

Upvotes: 0

Views: 119

Answers (2)

Álvaro González
Álvaro González

Reputation: 146460

  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//

Upvotes: 1

a1ex07
a1ex07

Reputation: 37364

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 ;

Upvotes: 0

Related Questions