CREATE DEFINER=`root`@`localhost` PROCEDURE `pro_nogoodsother`(num int , goodsId varchar(200),memberId INT,consumerId INT,p INT, oncePoint INT,comAmout INT ,canPoints INT )
BEGIN   
  DECLARE id INT ;   
  DECLARE lnumber INT ;   
  DECLARE STOP INT DEFAULT 0;   
  DECLARE cnt INT DEFAULT 0;   
  DECLARE tempId INT DEFAULT 0;  
   DECLARE maxId INT DEFAULT 0;          
  DECLARE flag INT DEFAULT 0;     
  DECLARE tId INT DEFAULT 0;   
 DECLARE asql  varchar(500);
 DECLARE cur CURSOR FOR SELECT * from newtt   ;
 DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET STOP=1;   
  SELECT ifnull(max(goodspointId),0)  INTO maxId FROM nogoodspointother;   
  SELECT loopNumber INTO lnumber FROM tbl_loop;     
 
  while num=5 do     
  DROP table IF EXISTS `newtt`;  
 
   if tempId<maxId then      
      begin      
          
           SET @asql=concat('create table newtt as select goodsPointId FROM nogoodspointother where goodsPointId >',tempId);
             PREPARE stml FROM @asql;
              EXECUTE stml;           
                   
            OPEN cur;     
           FETCH cur INTO id ;   
          WHILE STOP <> 1 DO             
        
        //略
                   
     FETCH cur INTO id;  
      END WHILE;  
     CLOSE cur;     
    end ;       
      end if ;      
           
     set flag=0;
end while ;
 END;
执行时报 newtt 不存在,是怎么回事呢?

解决方案 »

  1.   

    检查@asql中的内容,是否建立NEWTT表,没有满足条件的记录?
      

  2.   

    没问题的,当nogoodspointother  数据为空的时候运行没问题,当nogoodspointother 有数据运行就报
    newtt不存在。
      

  3.   

    sp有可能DROP table IF EXISTS `newtt然后就结束了吧
      

  4.   

    注意这句,如果没有满足条件的记录,会影响游标
    create table newtt as select goodsPointId FROM nogoodspointother where goodsPointId >',tempId分步调试显示TempId、maxId 中的值
      

  5.   

    没有值的时候到没问题,有值了就报newtt 不存在。调试不了,不输出。
      

  6.   

    TEMPID的值、
    直接在MYSQL中运行
    create table newtt as select goodsPointId FROM nogoodspointother where goodsPointId>值
    能否建表
      

  7.   

               SET @asql=concat('create table newtt as select goodsPointId FROM nogoodspointother where goodsPointId >',tempId);
               select @asql;
                 PREPARE stml FROM @asql;
                  EXECUTE stml;           
                       
                OPEN cur;     
               FETCH cur INTO id ;   
    加上这句看一下内容是什么。你的表newtt没有被创建。
      

  8.   

    create table newtt as select goodsPointId FROM nogoodspointother where goodsPointId >0;
    select *from newtt;
    执行这两句就报这样的错。表newtt不存在,怎么回事?
      

  9.   

    检查nogoodspointother表中是否有满足条件的记录
      

  10.   

    你的表应该是还没创建完毕。 与你 nogoodspointother表中是否有满足条件的记录 没有关系。
      

  11.   

               SET @asql=concat('create table newtt as select goodsPointId FROM nogoodspointother where goodsPointId >',tempId);
               select @asql;
                 PREPARE stml FROM @asql;
                 EXECUTE stml;          
               SELECT sleep(10);
               OPEN cur;    
              FETCH cur INTO id ;  先加个SLEEP试试,如果可以则需要在程序中加上循环以检查表是否创建完毕。
      

  12.   

    create table newtt as select goodsPointId FROM nogoodspointother where goodsPointId >0
    输出这个,但还报错。
      

  13.   

    create table newtt as select goodsPointId FROM nogoodspointother where goodsPointId >0;
    select *from newtt;
    其实这样试都不好使,那样也是一回事,这样创建怎么也不好使呢?
      

  14.   

    你直接在MYSQL执行这两句都不行?
      

  15.   

    select goodsPointId FROM nogoodspointother where goodsPointId >0
    有多少条记录
    在10万条记录中测试
    SET @ASQL='CREATE TABLE QQ.NEWTT AS SELECT * FROM JZG1 WHERE BH=\'101068\'';
    PREPARE STML FROM @ASQL;
    EXECUTE STML;
    SELECT * FROM QQ.NEWTT
    没有出现你的问题
    即使没有满足的条件记录,应该有1个没有记录的空表,
      

  16.   

    不行,执行不了,一样报newtt不存在。
      

  17.   

    如下贴出你的结果
    mysql> create table tx as select * from seqno where id<1;
    Query OK, 0 rows affected (0.03 sec)
    Records: 0  Duplicates: 0  Warnings: 0mysql>
      

  18.   

    我用的是root登录的,执行这两句就报错。