【发布时间】:2014-12-24 18:56:50
【问题描述】:
如果 NETEZZA 中存在表,我需要一个命令来删除该表,类似这样:
drop table if exists xxx;
我已经搜索并尝试了很多,但没有成功。你能帮帮我吗?
【问题讨论】:
-
为什么会有人投反对票?
标签: if-statement exists netezza
如果 NETEZZA 中存在表,我需要一个命令来删除该表,类似这样:
drop table if exists xxx;
我已经搜索并尝试了很多,但没有成功。你能帮帮我吗?
【问题讨论】:
标签: if-statement exists netezza
没有内置任何内容,但您可以创建一个存储过程,它使用目录视图在尝试删除表之前检查表是否存在:
create or replace procedure maybe_drop(varchar(128))
returns boolean
language nzplsql
as
begin_proc
declare
oname alias for $1;
o record;
begin
select otype into o
from (
select 'TABLE' otype from _v_table where tablename = upper(oname)
union all
select 'VIEW' otype from _v_view where viewname = upper(oname)
) x;
if found then
execute immediate 'DROP '||o.otype||' '||oname;
end if;
end;
end_proc;
【讨论】:
call maybe_drop('my_table'); 在单个语句中调用
在netezza 中,您可以使用以下语法:
drop table table_name if exists;
【讨论】: