能不能用一条语句实现,如果某表存在还是不存在都重新创建?

解决方案 »

  1.   

    Oracle创建表时,常遇到先删除后创建的情况,而它又没有drop table... if exists语法。为此可以使用user_objects数据字典和动态sql语句实现类似的功能,如下所示:
    create or replace procedure proc_dropifexists(
        p_table in varchar2 
    ) is
        v_count number(10);
    begin
       select count(*)
       into v_count
       from user_objects
       where object_name = upper(p_table);
       if v_count > 0 then
          execute immediate 'drop table ' || p_table ||' purge';
       end if;
    end;
      

  2.   

    sqlserver 可以 
    if exists(select 1 from sysobjects where name = 'tablename')
    drop table tablename但在oracle中没试过
      

  3.   

    了解了,确实这点没sqlserver方便,sqlserver里可以if object_id('表名') is not null   drop table 表名
      

  4.   

    oracle不行,只能用plsql多条语句