`
xinyoulinglei
  • 浏览: 123811 次
社区版块
存档分类
最新评论

oracle创建表浅先删除表 的实现

阅读更多
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'); ......

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics