求一个存储过程的写法

vgy12304 2012-08-03 05:41:06
目标是读取一个表是数据作为变量 来读另外一个表,红色的部分报错了,如果是读取多个字段,这里应该怎么写
DELIMITER $$

DROP PROCEDURE IF EXISTS `photo_db`.`proc_del_photo`$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `proc_del_photo`(
in p_id int(10),
in p_tablename char(20)
)
BEGIN
set @id=p_id;
set @size=0;
set @album_id=0;
/*
* using select photo_list
*/
set @q=concat('select album_id into @album_id,size into @size from ',p_tablename,' where id = ? ');
prepare sq from @q;
execute sq using @id;

/*
* using delete photo_list and update photo_ablum
*/
if(@album_id <> 0) then

set @q=concat('select * from photo_album where id = ? and size =? ');
prepare sq from @q;
execute sq using @album_id,@size;

end if;

deallocate prepare sq;
END$$

DELIMITER ;
...全文
91 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
ACMAIN_CHM 2012-08-06
  • 打赏
  • 举报
回复
set @q=concat('select album_id into @album_idsize into @size from ',p_tablename,' where id = ? ');

注意你这儿用了个什么符号,注意中文与英文的区别。

set @q=concat('select album_id into @album_id,size into @size from ',p_tablename,' where id = ? ');
WWWWA 2012-08-06
  • 打赏
  • 举报
回复
set @q=concat('select album_id,size into @album_id , @size from ',p_tablename,' where id = ? ');
vgy12304 2012-08-06
  • 打赏
  • 举报
回复
错误码: 1327
Undeclared variable: size
vgy12304 2012-08-06
  • 打赏
  • 举报
回复
错误码: 1327
Undeclared variable: size

第二个参数变量就不对了
vgy12304 2012-08-06
  • 打赏
  • 举报
回复
4楼正解。

同时谢谢5楼的,虽然你答的距离很远,还是谢谢你的热心回答
ACMAIN_CHM 2012-08-03
  • 打赏
  • 举报
回复
语法上没有问题,错误提示是什么? 一个语句返回多行了?

56,679

社区成员

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

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