Oracle创建表时,常遇到先删除后创建的情况,而它又没有drop table... if exists语法。为此可以使用user_objects数据字典和动态sql语句实现类似的功能,如下所示:
create or replace procedure proc_dropifexists(
p_table in varchar2
) is
v_count number(10);
begin
select count(*)
into v_count
from user_objects
where object_name = upper(p_table);
if v_count > 0 then
execute immediate 'drop table ' || p_table ||' purge';
end if;
end;
/
--调用
exec proc_dropifexists('mytable');
Oracle 的drop table if exists功能
最新推荐文章于 2024-04-20 19:58:40 发布