Home > Database > Mysql Tutorial > body text

oracle删除已存在的表的实例

WBOY
Release: 2016-06-07 17:56:02
Original
1336 people have browsed it

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

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;
/
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!