日期:2014-05-17  浏览次数:20855 次

判断表是否存在
判断表是否存在  
if   exists(select   table_name   from   user_tables   where   table_name= 'Thyc ')   hen
drop   table   Thyc;
end   if;
--这句不行
--下面这句也不行
declare
tcnt   number;
begin
select   count(*)   into   tcnt   from   user_tables   where   table_name= 'thyc ';
if   tcnt> 1   then
drop   table   Thyc;
else
dbms_output.put_line( '不存在! ');  
end   if;
end;
--新手呀,莫笑我


------解决方案--------------------
最后一行 打 "/ " 表示过程已经结束

而且过程中不一定会执行dbms_output.put_line( '不存在! '); 阿?

可以这样试一下:

set serveroutput on
declare
c_sql varchar2(4000);
begin
dbms_output.put_line( 'start ');
c_sql := 'drop table THYC ';
execute immediate c_sql;
exception
when OTHERS THEN
IF SQLCODE = -00942 THEN

dbms_output.put_line( '不存在! ');

END IF;
END ;
/