Select Count(*) Into IsExists from all_tables Where Trim(Table_Name)='TEMPAGTBALANCE'; IF IsExists=0 Then
   创建数据表;
 esle
   删除表中的数据;
end if;
?????????????????
如果本来表中就是空的,岂不是要报异常!
请问应怎样判断数据表已经存在?

解决方案 »

  1.   

    Select Count(*) Into IsExists from all_tables Where Trim(Table_Name)='TEMPAGTBALANCE';表不存在时count(*)=0
      

  2.   

    删除表中的数据;
    end if;
    ?????????????????
    如果本来表中就是空的,岂不是要报异常!
    请问应怎样判断数据表已经存在?
    =============
    执行动态sqlexecute immediate 'delete from ....';
      

  3.   

    Select Count(*) Into IsExists from all_tables Where Trim(Table_Name)='TEMPAGTBALANCE'; IF IsExists=0 Then
       execute immediate 'drop table xxxx';
       execute immediate 'create table xxxx';
     esle
       删除表中的数据;
    end if;
      

  4.   

    Select Count(*) Into IsExists from all_tables Where Trim(Table_Name)='rep_gtzhqk';
     IF IsExists=0 Then
     
    v_String1:='CREATE GLOBAL TEMPORARY TABLE rep_gtzhqk  (
    ncbh varchar2(20) null,
    ncmc varchar2(100) Null,
    nsbh varchar2(20) null,
                                nsmc varchar2(100) NULL,
                                nh varchar2(18) NULL,
                                eh varchar2(6) NULL ,
                                tc varchar2(2) NULL,
                                cdrq date null ,
                                mrts numeric(14,2) NULL, 
                                cnl numeric(14,2) NULL,
                                slwnl numeric(14,2) NULL,
                                rzlv numeric(14,2) NULL, 
                                rzl numeric(14,2) NULL,
                                dblv numeric(14,2) NULL,
                                dbl numeric(14,2) NULL,
                                rtlv numeric(14,2) NULL,
                                gwz numeric(14,2) NULL,
                                txbs numeric(14,2) NULL,
                                zxjs numeric(14,2) NULL,
                                sygly varchar2(100) null) 
    ON   COMMIT   PRESERVE   ROWS ' ;
    Execute Immediate v_String1; 
    else 
    execute immediate 'Truncate table rep_gtzhqk';
    end if;
    ======================================================
    我是这么创建的,第一次执行的时候没有错,第二次执行时报出java.sql.SQLException: ORA-00955: 名称已由现有对象使用
    说明,表已经存在了,为什么他还要创建.
      

  5.   

    Select Count(*) Into IsExists from all_tables Where Trim(Table_Name)='TEMPAGTBALANCE'; IF IsExists=0 Then
       execute immediate 'drop table xxxx';
       execute immediate 'create table xxxx';
     esle
       删除表中的数据;
    end if;
      

  6.   

    这样也不可以.
    如果表不存在的话,报ORA-14452: 试图创建, 更改或删除正在使用的临时表中的索引
      

  7.   

    Select Count(*) Into IsExists from all_tables Where Trim(Table_Name)='rep_gtzhqk';表名'rep_gtzhqk'全部大写