需求是这样的,表是按天生成的,例如table20110101,table20110102....
但是中间有可能某天的表不存在
这样,我按天循环insert的时候就会出错,请问怎么在insert的同时判断表是否存在,不存在就停止操作?

解决方案 »

  1.   

    关联 系统表,实例sql如下。看看
     select * information_schema.TABLES 
    where table_schema='test' and table_name='test';
      

  2.   


    create procedure sp()
    begin
       if exists(select 1 information_schema.TABLES where table_schema='test' and table_name='test') then
          insert into test values(1);
       end if;end;这样判断
      

  3.   


    create procedure sp()
    begin
       if exists(select 1 from information_schema.TABLES where table_schema='test' and table_name='test') then
          insert into test values(1);
       end if;end;
      

  4.   

    谢谢大家,我是这么解决的,用这个SQL语句“SHOW TABLES LIKE 'table%'”,找出所有匹配的表,然后在JAVA程序中按天循环,再从中匹配,这样就不会出错了