如题:  表名为A 
      1.判断A表存在,存在则先删除,然后创建A表
       2.判断A表不存在,创建表A 

解决方案 »

  1.   

    你的意思就是说要重新创建A表.在ORACLE中,不用这么判断.直接用CREATE OR REPLACE语句创建表,这样,既可以保留A表原有的权限,也可以使依赖该表的所有对象有效.如果是删除后再创建该表的话,则依赖于该表的所有对象都会无效,赋予别的用户的权限也要重新再赋予.
      

  2.   

    直接用CREATE   OR   REPLACE语句创建表?没有这种写法的吧
    select count(1) into v_counter from dba_tables where table_name='' and owner=''
    if v_counter=0 then
       v_sql:='create table tableName..'
       execute immediate v_sql;
    end if;
      

  3.   


    declare
        n number;
        v_sql varchar(200);
    begin
    select count(*) into n from user_tables where table_name = UPPER('your_table');
        if n>0 then 
           execute immediate 'drop table your_table';
        end if;
        
        v_sql := 'create table your_table(col1 varchar2(10),col2 varchar2(20))';
        execute immediate v_sql;
        
    exception
    when others then
    null;
    end;
      

  4.   

    多谢 microsoft_fly 指出我的错误,原来ORACLE 真的还不支持CREATE OR REPLACE TABLE这个语句,但可以用CREATE OR REPLACE命令创建其它的一些数据库对象(视图,过程等)
      

  5.   

    之所以用OR REPLACE选项,而不是先DROP 再 CREATE 的理由与我上面所说的一样,这也是用OR REPLACE 选项的好处