Oracle 如果我删除了一个表,而该表不存在,我会得到一个错误
我需要放下一张桌子,做一张新的。如果我删除了该表,而该表不存在,我会得到一个错误 如何检查该表是否存在 我正在研究Oracle 11g 提前谢谢。类似的Oracle 如果我删除了一个表,而该表不存在,我会得到一个错误,oracle,oracle11g,Oracle,Oracle11g,我需要放下一张桌子,做一张新的。如果我删除了该表,而该表不存在,我会得到一个错误 如何检查该表是否存在 我正在研究Oracle 11g 提前谢谢。类似的 select count(*) from user_tables where table_name= :table name 或 或者是一个严厉的替代方案: begin execute immediate 'drop table table_name'; exception when others then null; end; 差不
select count(*) from user_tables
where table_name= :table name
或
或者是一个严厉的替代方案:
begin execute immediate 'drop table table_name';
exception when others then null;
end;
差不多
select count(*) from user_tables
where table_name= :table name
或
或者是一个严厉的替代方案:
begin execute immediate 'drop table table_name';
exception when others then null;
end;
你可以这样做:
DECLARE v_exist PLS_INTEGER;
BEGIN
SELECT COUNT(*) INTO v_exist
FROM user_tables
WHERE table_name = 'YOURTABLEHERE';
IF v_exist = 1 THEN
EXECUTE IMMEDIATE 'DROP TABLE YOURTABLEHERE';
END IF;
你可以这样做:
DECLARE v_exist PLS_INTEGER;
BEGIN
SELECT COUNT(*) INTO v_exist
FROM user_tables
WHERE table_name = 'YOURTABLEHERE';
IF v_exist = 1 THEN
EXECUTE IMMEDIATE 'DROP TABLE YOURTABLEHERE';
END IF;
我一直在使用以下程序来处理此问题:
create or replace procedure drop_table_if_exists ( p_table_name varchar2 )
is
it_exist number;
begin
select count(*)
into it_exists
from user_tables
where table_name = p_table_name
;
if it_exists >= 1 then
execute immediate 'drop table '||p_table_name;
end if;
end;
/
exec drop_table_if_exists ( 'TABLE_TO_DROP' );
我一直在使用以下程序来处理此问题:
create or replace procedure drop_table_if_exists ( p_table_name varchar2 )
is
it_exist number;
begin
select count(*)
into it_exists
from user_tables
where table_name = p_table_name
;
if it_exists >= 1 then
execute immediate 'drop table '||p_table_name;
end if;
end;
/
exec drop_table_if_exists ( 'TABLE_TO_DROP' );
分享和享受
共享和享受。获取错误并不是世界末日-如果表不存在,您可以使用异常处理程序处理错误。获取错误的可能重复并不是世界末日-如果表不存在,您可以使用异常处理程序处理错误。可能重复的