这样写不成:
if exists (select * from tabs where table_name='test_table') then
drop table test_table;
end if;
表存在的时候不报错,不存在的时候报错:ORA-00942: table or view does not exist
是IF写的不对?
...全文
4042打赏收藏
ORACLE里如何在drop前判断表是否存在
这样写不成: if exists (select * from tabs where table_name='test_table') then drop table test_table; end if; 表存在的时候不报错,不存在的时候报错:ORA-00942: table or view does not exist 是IF写的不对?
declare
w_count int;
w_name varchar2(20);
begin
w_name := 'tablemname';
select count(*) into w_count from user_tables where name=w_name;
if (w_count>0) then
execute immediate 'drop table '|| w_name;
end if;
end;