您的位置:首页 > 数据库 > Oracle

oracle drop table 之前的if exists判断

2010-08-11 20:48 393 查看

   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'); ......

阅读更多
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: