ITeye博客

oracle drop table 之前的if exists判断

wangxizhao · 2010-08-11 20:48 · 数据库 · MySQL · Oracle · Markdown

oracle语法中没有mysql语法中的drop table  table_name if exists 这种形式,但是我们可以曲线救国,使用orale的存储过程实现同样的效果,下面给出具体做法:

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 ||' cascade constraints';
   end if;
end;
/
--调用
exec proc_dropifexists('mytable'); ......

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。