我正试图编写一个mysql程序来修复我的数据库问题。
目前有两个表与此问题相关:
pre_forum_thread-这是一个表,它保存关于有多少回复链接到一个帖子的信息。
pre_forum_post-这是post数据库。
我写的程序如下:
delimiter //
create procedure fix_position()
begin
declare t int(10);
declare b int(10);
declare c int(10);
DECLARE thread_id CURSOR FOR select tid from pre_forum_thread;
open thread_id;
fetch thread_id into t;
SELECT count(*) into b FROM pre_forum_post WHERE tid=t;
set c= b - 1;
UPDATE pre_forum_thread SET replies= c WHERE tid=t;
UPDATE pre_forum_thread SET maxposition=b WHERE tid=t;
CLOSE thread_id;
end;//
DELIMITER ;
但是当我调用这个过程时,我得到了一个错误:
Out of range value for column 'replies' at row 1
我把程序改成
DECLARE thread_id CURSOR FOR select tid from pre_forum_thread;
open thread_id;
fetch thread_id into t;
SELECT count(*) into b FROM pre_forum_post WHERE tid=t;
UPDATE pre_forum_thread SET maxposition=b WHERE tid=t;
CLOSE thread_id;
我搞错了
ERROR 1329 (02000): No data - zero rows fetched, selected, or processed
看起来两个“更新”都不起作用…
有人能帮忙吗?