0

I'm getting following error while creating stored procedure in mysql like as follows

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 '' at line 8

Bellow one is my stored procedure

mysql> delimiter //

mysql> create procedure music_procedure(in movie_name varchar(100),in movie_image varchar(100),in music_director varchar(150),in cast varchar(150),in songtitle varchar(150),in duration time,in artist varchar(100),in lyricist varchar(100),in status varchar(50))

-> begin

->  if not exists (select movie_name from music where music.movie_name=movie_name) then

-> insert into music(movie_name,movie_image,music_director,cast) values(movie_name,movie_image,music_director,cast);

-> insert into music_details(songtitle,duration,artist,lyricist,status,music_id) values(songtitle,duration,artist,lyricist,status,(select music_id from music where music.movie_name=movie_name));

 -> else

-> insert into music_details(songtitle,duration,artist,lyricist,status,music_id) values(songtitle,duration,artist,lyricist,status,(select music_id from music where music.movie_name=movie_name));


-> end


-> //
1
  • 3
    I don't see an end if Commented Aug 2, 2013 at 6:07

2 Answers 2

1

add end if; in the your code

mysql> delimiter //

mysql> create procedure music_procedure(in movie_name varchar(100),in movie_image varchar(100),in music_director varchar(150),in cast varchar(150),in songtitle varchar(150),in duration time,in artist varchar(100),in lyricist varchar(100),in status varchar(50))

-> begin

->  if not exists (select movie_name from music where music.movie_name=movie_name) then

-> insert into music(movie_name,movie_image,music_director,cast) values(movie_name,movie_image,music_director,cast);

-> insert into music_details(songtitle,duration,artist,lyricist,status,music_id) values(songtitle,duration,artist,lyricist,status,(select music_id from music where music.movie_name=movie_name));

 -> else

-> insert into music_details(songtitle,duration,artist,lyricist,status,music_id) values(songtitle,duration,artist,lyricist,status,(select music_id from music where music.movie_name=movie_name));


-> end if;


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

1 Comment

You also need the end to match begin.
0

You're simply missing END IF;. Put it just before your END statement;

1 Comment

That shouldn't matter, whitespace is inignificant.

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.