If statement 如果netezza中存在,则删除

If statement 如果netezza中存在,则删除,if-statement,exists,netezza,If Statement,Exists,Netezza,如果NETEZZA中存在表,我需要一个命令来删除该表,类似于: drop table if exists xxx; 我已经搜索并尝试了很多次,但都没有成功。您能在这里帮助我吗?没有内置内容,但您可以创建一个存储过程,该过程使用目录视图检查表是否存在,然后再尝试删除它: create or replace procedure maybe_drop(varchar(128)) returns boolean language nzplsql as begin_proc declar

如果NETEZZA中存在表,我需要一个命令来删除该表,类似于:

drop table if exists xxx;

我已经搜索并尝试了很多次,但都没有成功。您能在这里帮助我吗?

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

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;

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

drop table table_name if exists;

为什么有人会投票否决它?实际上我需要一个SQL cmd,应该直接使用它作为查询?你不能在nzplsql之外进行,这意味着你需要创建存储过程。创建存储过程后,可以使用
call maybe_drop('my_table')在单个语句中调用存储过程谢谢你们的回复,伙计们:)这在7.2.0的开始部分就出现了