我在mysql中创建存储过程时遇到以下错误,如下所示
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是我的存储过程
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
-> //
答案 0 :(得分:1)
在您的代码中添加end if;
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;
-> //
答案 1 :(得分:0)
你只是遗漏了END IF;
。把它放在END
声明之前;