Oracle没有drop table if exists ,使用存储过程实现。
-- 定义存储过程
create or replace procedure proc_droptable(
p_table in varchar2
) is
v_count number(10);
begin
select count(*) into v_count from user_tables
where table_name = upper(p_table);
if v_count > 0 then
execute immediate 'drop table ' || p_table ||' purge';
end if;
end proc_droptable;
-- 调用执行过程
exec proc_droptable('tableName');