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

解决方案 »

  1.   

    类似的东西我在sql server上都做过
    一切正常,怎么到了mysql总出毛病呢
      

  2.   

    按说TEMPORARY的表在每次存储过程执行结束以后就自动销毁了
    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 应该可以删除
      

  3.   

    我在存储过程的最后也写了drop table tmp_table15了,可是再次运行还是老样子
    如果说是 关闭连接时DROP
    那不是说一个创建临时表的存储过程在一次连接中只能使用一次吗?这个好像不大合理啊
      

  4.   

    如果是上述代码的话,你DROP的是
    drop table tmp_table2

    tmp_table15
      

  5.   

    drop table tmp_table2; 
      

  6.   

    drop table tmp_table15这个我运行的时候已经改过来了
    但是还是不行
    到底是为什么啊
      

  7.   

    Do you have privilege to drop your temporary table?
      

  8.   

    是否在其他地方有用到tmp_table15表的地方,把表锁住了。
    我就奇怪了,你每次都要生成相同的表结构,为什么不只是每次清空表,然后插入数据?非要每次删除表!
      

  9.   

    Move this statement drop table tmp_table2 to the beginning of your procedure. 
    Use statement drop table if exists tmp_table2 is better.
      

  10.   

    我试图使用你的方法,在存储过程的前面加上如果表已经存在就删除这个表
    可是运行的时候,总是报“未知的table tmp_table21 ”
    这是为什么啊?教我一下好吗
    if exists TEMPORARY table tmp_table21 then
    drop TEMPORARY table tmp_table21;
    end if;
      

  11.   

    DROP TEMPORARY TABLE  
    IF EXISTS tmp_table21;
        
      

  12.   

    仔细检查!!!!!我给你修改的。delimiter ||
    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 ;