Drop if exists in netezza

无人久伴 提交于 2019-12-10 17:23:15

问题


I need a command to delete a table if that exists in NETEZZA, Something like that:

drop table if exists xxx;

I have searched and tried many but it didn't work. Can you help me here?


回答1:


In netezza you can use this syntax:

drop table table_name if exists;



回答2:


There is nothing built-in, but you can create a stored proc which uses the catalog views to check if the table exists before attempting to drop it:

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;


来源:https://stackoverflow.com/questions/26624118/drop-if-exists-in-netezza

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!