2014-10-29 2 views

답변

3

가 내장 아무것도 없다,하지만 당신은 테이블을 드롭하기 전에 존재하는지 확인하기 위해 카탈로그 뷰를 사용하는 저장된 프로 시저 만들 수 있습니다 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; 
+0

사실 나는 SQL cmd를 가지고 있어야하며 이것을 쿼리로 직접 사용해야합니까? – Harry

+0

nzplsql 외부에서는 실행할 수 없습니다. 즉, sproc을 작성해야합니다. sproc이 생성되면'call maybe_drop ('my_table');을 사용하여 단일 명령문을 호출 할 수 있습니다. – qSlug

+0

응답 주셔서 감사합니다 :) – Harry

12

는이 구문을 사용 할 수 있습니다 :

drop table table_name if exists; 
+0

이것은 [docs] (https://www.ibm. com/support/knowledgecenter/SSULQD_7.2.1/com.ibm.nz.dbu.doc/r_dbuser_drop_table.html) 7.2.0부터 시작하십시오. – Niederee