如果 netezza 中存在则删除

问题描述 投票:0回答:3

我需要一个命令来删除表(如果NETEZZA中存在该表),类似的东西:

drop table if exists xxx;

我已经搜索并尝试了很多,但没有成功。你能帮我一下吗?

if-statement exists netezza
3个回答
17
投票

netezza
中,您可以使用以下语法:

drop table table_name if exists;

3
投票

没有任何内置内容,但您可以创建一个存储过程,它使用目录视图在尝试删除表之前检查表是否存在:

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;

© www.soinside.com 2019 - 2024. All rights reserved.