0

在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

下面是我的存储过程

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


-> //
4

2 回答 2

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;


-> //
于 2013-08-02T06:07:41.677 回答
0

你只是失踪了END IF;。把它放在你的END陈述之前;

于 2013-08-02T06:06:05.493 回答