mysql存储过程创建失败
CREATEPROCEDUREGetType()begindeclareTypeint;if(Type=1)beginselecttop4*fromProductwher...
CREATE PROCEDURE GetType()
begin
declare Type int;
if(Type=1)
begin
select top 4 * from Product where Hot='热卖' order by id desc;
end
else if(Type=2)
begin
select top 4 * from Product where Jipin='精品' order by id desc;
end
else if(Type=3)
select top 4 * from Product where Tejia='特价' order by id desc;
end
//
好像是中文乱码问题
谢谢底下二位了 展开
begin
declare Type int;
if(Type=1)
begin
select top 4 * from Product where Hot='热卖' order by id desc;
end
else if(Type=2)
begin
select top 4 * from Product where Jipin='精品' order by id desc;
end
else if(Type=3)
select top 4 * from Product where Tejia='特价' order by id desc;
end
//
好像是中文乱码问题
谢谢底下二位了 展开
2个回答
展开全部
你的存储过程好多语法错误,试试下面这个:
delimiter //
CREATE PROCEDURE GetType(IN Type int)
begin
if Type=1 then
select top 4 * from Product where Hot='热卖' order by id desc;
elseif Type=2 then
select top 4 * from Product where Jipin='精品' order by id desc;
elseif Type=3 then
select top 4 * from Product where Tejia='特价' order by id desc;
end if
end
//
delimiter ;
delimiter //
CREATE PROCEDURE GetType(IN Type int)
begin
if Type=1 then
select top 4 * from Product where Hot='热卖' order by id desc;
elseif Type=2 then
select top 4 * from Product where Jipin='精品' order by id desc;
elseif Type=3 then
select top 4 * from Product where Tejia='特价' order by id desc;
end if
end
//
delimiter ;
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
你写的是Sqlserver的语法呀,我给你写个mysql的吧:
CREATE PROCEDURE GetType(in type int)
begin
if(Type=1) then
select * from Product where Hot='热卖' order by id desc limit 4;
elseif (Type=2) then
select * from Product where Jipin='精品' order by id desc limit 4;
elseif (Type=3) then
select * from Product where Tejia='特价' order by id desc limit 4;
end if;
end;我测试通过了
CREATE PROCEDURE GetType(in type int)
begin
if(Type=1) then
select * from Product where Hot='热卖' order by id desc limit 4;
elseif (Type=2) then
select * from Product where Jipin='精品' order by id desc limit 4;
elseif (Type=3) then
select * from Product where Tejia='特价' order by id desc limit 4;
end if;
end;我测试通过了
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询