当前位置:   article > 正文

oracle表已存在,oracle如何删除已存在的表

oracle删除表如果存在

你知道oracle如何删除已存在的表吗?我们经常会需要在oracle中删除已存在的表,但是有很多小伙伴们都是不知道如何操作的,今天爱站小编就为大家详细介绍删除已存在的表的方法。

Sql代码

复制代码 代码如下:

select count(*) from user_objects where object_name=upper(p_table_name);

select count(*) from user_tables where table_name=upper(p_table_name);

create or replace procedure p_drop_table_if_exist_v1(

p_table_name in varchar2

) is

v_count number(10);

begin

select count(*)

into v_count

from user_objects

where object_name=upper(p_table_name);

if v_count > 0 then

execute immediate 'drop table ' || p_table_name || ' purge';

end if;

exception

when no_data_found then

begin

null;

end;

end;

/

create or replace procedure p_drop_table_if_exist_v2(

p_table_name in varchar2

) is

v_table_name varchar2(20);

begin

select table_name

into v_table_name

from user_tables

where table_name=upper(p_table_name);

if length(v_table_name)>0 then

execute immediate 'drop table ' || p_table_name || ' cascade constraints';

end if;

exception

when no_data_found then

begin

null;

end;

end;

/

以上就是关于oracle如何删除已存在的表的内容, 是不是很多小伙伴们被此问题困扰过,那么在看完本文后有相同问题的朋友可以借此方法来解决此问题。

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Cpp五条/article/detail/440823
推荐阅读
相关标签
  

闽ICP备14008679号