首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > 其他数据库 >

剔除已存在的表

2013-03-06 
删除已存在的表查询系统表,判断表是否存在,存在则直接删除select count(*)from user_objects where object

删除已存在的表

查询系统表,判断表是否存在,存在则直接删除

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) isv_count number(10);beginselect count(*)into v_countfrom user_objectswhere object_name=upper(p_table_name);if v_count > 0 thenexecute immediate 'drop table ' || p_table_name || ' purge';end if;exceptionwhen no_data_found then    begin        null;    end;end;/ create or replace procedure p_drop_table_if_exist_v2(p_table_name in varchar2) isv_table_name varchar2(20);beginselect 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;exceptionwhen no_data_found then    begin        null;    end;end;/ 

热点排行