declare
num number;
begin
select count(1) into num from all_tables where TABLE_NAME = 'TNAME';
if num>1 then
drop table tname;
end if;
end;
/

解决方案 »

  1.   

    可是,该脚本无法在worksheet中正确执行:(
    需要在worksheet中可以正确执行,不抛出错误~~~
      

  2.   

    worksheet没用过
    你在sql*plus里面运行
      

  3.   

    sql*plus以下是错误描述:
    drop table units;
    *
    ERROR 位于第 6 行:
    ORA-06550: 第 6 行, 第 1 列:
    PLS-00103: 出现符号 "DROP"在需要下列之一时:
    begin case declare exit
    for goto if loop mod null pragma raise return select update
    while with <an identifier>
    <a double-quoted delimited-identifier> <a bind variable> <<
    close current delete fetch lock insert open rollback
    savepoint set sql execute commit forall merge
    <a single-quoted SQL string> pipe
      

  4.   

    用dba用户赋税权限grant drop any table to user_name;SQL> declare
      2  num number;
      3  begin
      4  select count(1) into num from all_tables where TABLE_NAME = 'BB';
      5  if num=1 then
      6  execute immediate 'drop table bb';
      7  end if;
      8  end;
      9  /PL/SQL procedure successfully completed
      

  5.   

    sorry
    beckham的对,要用动态sql
      

  6.   

    hehe~~3x every one:)
    看来分要给beckham了:~~