疑难杂症啊。存储过程里指定删除条件,却将我数据都删除掉啦

jianshao810 2012-11-23 03:12:23

create procedure p_AddArtisType(isAdd int,aId varchar(50),tIds varchar(500) )
BEGIN
if isAdd=1 then
if tIds!='' then
set @updatesql =CONCAT(' insert into artiststype(AId,TId,IdPath,NamePath) select ',aId,',ID,FullID,FullName from t_part_info where ID in(',tIds,')');
PREPARE sqltext from @updatesql;
execute sqltext;
end if;
else

if tIds!='' then
delete from artiststype where AId=cast(aId as unsigned);
commit;
/*
set @updatesql =CONCAT('insert into artiststype(AId,TId,IdPath,NamePath) select ',aId,',ID,FullID,FullName from t_part_info where ID in(',tIds,');');
PREPARE sqltext from @updatesql;
execute sqltext;
*/
end if;
end if;
END

执行 call p_AddArtisType(0,'10','15,16')
结果把所有数据都删除掉。
真被他搞死啦
...全文
59 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
jianshao810 2012-11-23
  • 打赏
  • 举报
回复
真的很感谢你
wwwwb 2012-11-23
  • 打赏
  • 举报
回复
注意变量名与字段名不要重名, create procedure p_AddArtisType(isAdd int,aId1 varchar(50),tIds varchar(500) ) BEGIN if isAdd=1 then if tIds!='' then set @updatesql =CONCAT(' insert into artiststype(AId,TId,IdPath,NamePath) select ',aId,',ID,FullID,FullName from t_part_info where ID in(',tIds,')'); PREPARE sqltext from @updatesql; execute sqltext; end if; else if tIds!='' then delete from artiststype where AId=0+aId1; commit; /* set @updatesql =CONCAT('insert into artiststype(AId,TId,IdPath,NamePath) select ',aId,',ID,FullID,FullName from t_part_info where ID in(',tIds,');'); PREPARE sqltext from @updatesql; execute sqltext; */ end if; end if; END

56,679

社区成员

发帖
与我相关
我的任务
社区描述
MySQL相关内容讨论专区
社区管理员
  • MySQL
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧