0

I am have created function in mysql.

This is code of my function

 DROP FUNCTION `star`//

CREATE DEFINER=`root`@`localhost` FUNCTION `star`(
num INT

) RETURNS int(11)
DETERMINISTIC
 BEGIN

                IF(num>=0 && num<20)
                THEN
                RETURN 1;
                ELSEIF(num>=20 && num<40)
                THEN
                RETURN 2;
                ELSEIF(num>=40 && num<60)
                THEN
                RETURN 3;
                ELSEIF(num>=60 && num<80)
                THEN
                RETURN 4;
                ELSEIF(num>=80 && num<=100)
                THEN
                RETURN 5;
                END IF;
    END

I have forgotten how did i made this function in my database. Now i want to create same function into another database.

For this i just copy above code and paste that in sql. and press Go. But it creates error. Please tell me what mistake i have done.

3
  • What's the error output? Commented Feb 14, 2012 at 10:00
  • MySQL said: #1064 - 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 '// CREATE DEFINER=root@localhost FUNCTION star( num int )' at line 1 Commented Feb 14, 2012 at 10:02
  • When i remove my first line of code then i creates problem in if condition. I dont know whats happening here. Even i created same procedure in one database then why this is creating problem into another database. Commented Feb 14, 2012 at 10:03

1 Answer 1

1

You need a DELIMITER // statement at the top...

Sign up to request clarification or add additional context in comments.

Comments

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.