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');
本文介绍了一种在Oracle数据库中实现类似“DROP TABLE IF EXISTS”的方法。通过创建存储过程来检查表是否存在,并在存在的情况下执行DROP操作。这种方法可以有效避免因表不存在而引发的错误。

被折叠的 条评论
为什么被折叠?



