---
title: "oracle drop table 之前的if exists判断"
author: "wangxizhao"
date: "2010-08-11T20:48:48Z"
tags: ["MySQL", "Oracle"]
categories: ["数据库"]
slug: "oracle-drop-table-if-exists"
draft: false
lastmod: "2010-08-11T20:50:15Z"
id: 734875
url: "https://wangxizhao.iteye.com/blog/734875"
---

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 &gt; 0 then  
      execute immediate 'drop table ' || p\_table ||' cascade constraints';  
   end if;  
end;  
/  
\--调用  
exec proc\_dropifexists('mytable'); ......