oracle删除已存在的表的实例
2019/6/30 21:19:53
本文主要是介绍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;
/
复制代码 代码如下:
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删除已存在的表的实例的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!