delimiter //
drop procedure if exists createflowtable_UL//
create procedure createflowtable_UL ()  BEGIN
    declare tablesql varchar(300);
    declare timesql varchar(20);
    
    set timesql =  CONCAT (MONTH (now()),'-',DAY (now()),'_',hour (now()));
    set tablesql = CONCAT ('create table flow_agent8_job2_UL_',timesql,
 '( ULthroughput FLOAT(12,4),',
 'max_rate FLOAT(12,8),',
'eNB VARCHAR(20) )',
' ENGINE=MyISAM DEFAULT CHARSET=latin1');
 set @s := tablesql;
 prepare statement from @s;
 execute statement;
 
   END
  //
delimiter ;
调用该存储过程时,怎么生成不了表?

解决方案 »

  1.   

    delimiter //
    drop procedure if exists createflowtable_UL//
    create procedure createflowtable_UL () BEGIN
       declare tablesql varchar(300);
       declare timesql varchar(20);
      
       set timesql =  CONCAT (MONTH (now()),'-',DAY (now()),'_',hour (now()));
       set tablesql = CONCAT ('`create table flow_agent8_job2_UL_',timesql,
     '`( ULthroughput FLOAT(12,4),',
     'max_rate FLOAT(12,8),',
    'eNB VARCHAR(20) )',
    ' ENGINE=MyISAM DEFAULT CHARSET=latin1;');
     set @s := tablesql;
     prepare statement from @s;
     execute statement;
      
      END
     //
    delimiter ;
      

  2.   

    生成不了表啊,去掉timesql后就可以生成表。是变量出问题了么?
      

  3.   

    改成如下,贴出结果。delimiter //
    drop procedure if exists createflowtable_UL//
    create procedure createflowtable_UL ()  BEGIN
      declare tablesql varchar(300);
      declare timesql varchar(20);
        
      set timesql =  CONCAT (MONTH (now()),'-',DAY (now()),'_',hour (now()));
      set tablesql = CONCAT ('`create table flow_agent8_job2_UL_',timesql,
     '`( ULthroughput FLOAT(12,4),',
     'max_rate FLOAT(12,8),',
    'eNB VARCHAR(20) )',
    ' ENGINE=MyISAM DEFAULT CHARSET=latin1;');
     set @s := tablesql;
    select @sql;
     prepare statement from @s;
     execute statement;
     
     END
      //
    delimiter ;
      

  4.   

    我找到原因了,mysql数据库的表名,不能有‘-’这个符号。还是谢谢你和我一起思考,分给你了