begin
  if exists(select * from user_tables where table_name = 'TMP_ST')  then 
  execute immediate 'drop table TMP_ST';
end if;
end;
这段SQL为什么会报错?错误显示"function or pseudo-column 'EXISTs' may be used inside a SQL statement only"exists只能用在sql语句里?

解决方案 »

  1.   


    --你的写法是MSSQL的语法,Oracle不支持
    declare
    cnt number;
    begin
      select Count(*) into cnt from user_tables where table_name = 'TMP_ST' ;
      if cnt>0  then 
        execute immediate 'drop table TMP_ST';
      end if;
    end;
      

  2.   

    の  好像没见过额   学习了select count(*) into l_row from user_tables where table_name = 'TMP_ST';
    if l_row >0 then 
      execute immediate 'drop table TMP_ST';
    end if;
      

  3.   

    --oracle不是这样的语法 
    declare
    cnt number;
    begin
      select count(*) into cnt from user_tables where table_name = 'TMP_ST';
    if cnt>0 then 
      execute immediate 'drop table TMP_ST';
    end if;
    end;