BEGIN
declare idlower bigint;
declare idupper bigint;
declare totalreccount int;
declare mymod bigint;
CREATE TEMPORARY TABLE tmp_table15 (
rowid bigint auto_increment primary key,
userid bigint);insert into tmp_table15 (userid) select ID from restcomments;
set idlower=(pageno-1)*pagesize+1;
set idupper=pageno*pagesize;
select * from tmp_table15;/*计算总页数*/
select count(*) from tmp_table12 into totalreccount;
set pagecount=totalreccount;
drop table tmp_table2;按说TEMPORARY的表在每次存储过程执行结束以后就自动销毁了,可是我这个存储过程每次执行过后再执行都说“tmp_table15 已存在”,我设置了tmp_table15 是临时的了啊,怎么执行完以后还会存在呢?
在数据库的表中还看不到这个表,连用drop tmp_table15都不行,到底是为什么啊
END
declare idlower bigint;
declare idupper bigint;
declare totalreccount int;
declare mymod bigint;
CREATE TEMPORARY TABLE tmp_table15 (
rowid bigint auto_increment primary key,
userid bigint);insert into tmp_table15 (userid) select ID from restcomments;
set idlower=(pageno-1)*pagesize+1;
set idupper=pageno*pagesize;
select * from tmp_table15;/*计算总页数*/
select count(*) from tmp_table12 into totalreccount;
set pagecount=totalreccount;
drop table tmp_table2;按说TEMPORARY的表在每次存储过程执行结束以后就自动销毁了,可是我这个存储过程每次执行过后再执行都说“tmp_table15 已存在”,我设置了tmp_table15 是临时的了啊,怎么执行完以后还会存在呢?
在数据库的表中还看不到这个表,连用drop tmp_table15都不行,到底是为什么啊
END
一切正常,怎么到了mysql总出毛病呢
NO,MYSQL停止运行
OR
A TEMPORARY table is visible only to the current connection, and is dropped automatically
when the connection is closed关闭连接时DROP用DROP TABLE 应该可以删除
如果说是 关闭连接时DROP
那不是说一个创建临时表的存储过程在一次连接中只能使用一次吗?这个好像不大合理啊
drop table tmp_table2
非
tmp_table15
但是还是不行
到底是为什么啊
我就奇怪了,你每次都要生成相同的表结构,为什么不只是每次清空表,然后插入数据?非要每次删除表!
Use statement drop table if exists tmp_table2 is better.
可是运行的时候,总是报“未知的table tmp_table21 ”
这是为什么啊?教我一下好吗
if exists TEMPORARY table tmp_table21 then
drop TEMPORARY table tmp_table21;
end if;
IF EXISTS tmp_table21;
create procedure sp_test1(
IN pageno int, IN pagesize int,
OUT pagecount int
)
BEGIN
declare idlower bigint;
declare idupper bigint;
declare totalreccount int; drop table if exists tmp_table21;
CREATE TEMPORARY TABLE tmp_table21(
rowid bigint auto_increment primary key,
userid bigint
);
insert into tmp_table21 (userid) select ID from restcomments;
set idlower=(pageno-1)*pagesize+1;
set idupper=pageno*pagesize;
select * from tmp_table21; /*计算总页数*/
select count(*) from tmp_table21 into totalreccount;
set pagecount=totalreccount;
end||
delimiter ;