oracle刪除已存在的表的實(shí)例
更新時(shí)間: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ù)庫自動(dòng)存儲(chǔ)管理-安裝配置
關(guān)于ASM的討論很多,但是到底什么是ASM?ASM是一個(gè)有效的抽象層,使你的Oracle數(shù)據(jù)庫可以與叫做diskgroups的抽象空間一起使用,而不是直接使用datafiles。2009-05-05
在ORACLE中SELECT TOP N的實(shí)現(xiàn)方法
這篇文章主要介紹了在ORACLE中SELECT TOP N的實(shí)現(xiàn)方法,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友參考下2017-01-01
oracle 虛擬專用數(shù)據(jù)庫詳細(xì)介紹
這篇文章詳細(xì)介紹了oracle 虛擬專用數(shù)據(jù)庫,對(duì)行級(jí)別和列級(jí)別分別舉了代碼實(shí)例并進(jìn)行分析,內(nèi)容比較詳細(xì),需要的朋友可以參考下。2017-09-09
oracle 9i使用閃回查詢恢復(fù)數(shù)據(jù)庫誤刪問題
本篇文章給大家介紹在oracle 9i中使用閃回查詢恢復(fù)數(shù)據(jù)庫誤刪問題,涉及到數(shù)據(jù)庫增刪改查的基本操作,對(duì)oracle數(shù)據(jù)庫閃回查詢感興趣的朋友可以一起學(xué)習(xí)下本篇文章2015-10-10
Oracle 左連接(+)加號(hào)用法及常用語法之間的關(guān)系
通過分析左連接(+)加號(hào)的寫法和一些常用語法之間的聯(lián)系,了解到Oracle 加號(hào)(+)的用法。本文重點(diǎn)給大家介紹Oracle 左連接(+)加號(hào)用法及常用語法之間的關(guān)系 ,感興趣的朋友跟隨小編一起看看吧2018-10-10

