oracle用存储过程实现mysql的drop if exists

以下oralce存储过程作用类似于mysql的 drop if exists功能。
--判断制定表是否存在,如果存在删除该表。
create or replace procedure proc_dropifexists(   
    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_dropifexists;

在调用存储过程的时候出了点小问题。在PLSQL中执行以上存储过程,网上很多文章都
用     exec proc_dropifexists('表名');
或者   execute proc_dropifexists('表名');
来执行。但本人在执行以上语句的时候总是报'ora 00900' 无效语句错误,不知为何。

最后用:  call proc_dropifexists('表名'); 执行成功。

不知道以上原理是什么,如果有懂原理的大神看到,请指教。

猜你喜欢

转载自lafecat.iteye.com/blog/2163081
今日推荐