oracle刪除已存在的表的實例
更新時間:2013年02月28日 10:55:01 作者:
查詢系統(tǒng)表,判斷表是否存在,存在則直接刪除
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;
/
復(fù)制代碼 代碼如下:
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;
/
相關(guān)文章
Oracle數(shù)據(jù)庫批量變更字段類型的實現(xiàn)步驟
我有個項目使用Oracle數(shù)據(jù)庫,運行幾年后數(shù)據(jù)量較大,需要對數(shù)據(jù)庫做一次優(yōu)化,其中有些字段類型類型需要調(diào)整,這里分享一下實現(xiàn)步驟,感興趣的朋友可以參考下2024-02-02JDBC Oracle執(zhí)行executeUpdate卡死問題的解決方案
今天小編就為大家分享一篇關(guān)于JDBC Oracle執(zhí)行executeUpdate卡死問題的解決方案,小編覺得內(nèi)容挺不錯的,現(xiàn)在分享給大家,具有很好的參考價值,需要的朋友一起跟隨小編來看看吧2018-12-12oracle中得到一條SQL語句的執(zhí)行時間的兩種方式
這篇文章主要介紹了oracle中如何得到一條SQL語句的執(zhí)行時間,有兩種可行方式,大家可以參考下2014-05-05Oracle Linux 6.8安裝 mysql 5.7.17的詳細(xì)教程
這篇文章主要介紹了Oracle Linux 6.8安裝 mysql 5.7.17的詳細(xì)教程,需要的朋友可以參考下2017-06-06PL/SQL中編寫Oracle數(shù)據(jù)庫分頁的存儲過程
這篇文章主要介紹了 PL/SQL中編寫Oracle數(shù)據(jù)庫分頁的存儲過程,非常不錯,具有參考借鑒價值,需要的朋友可以參考下2017-06-06