Check for UK before creating a

0

I have the following query:

alter table FINALIDADE_OPERACAO_MODAL 
        add constraint UK_t127pwh154arjh5whq0g4dlrm unique (NOME);

As I create a function that checks if it exists before, and if it does not exist, it creates, and if it already exists, it exits the command.

    
asked by anonymous 26.09.2016 / 19:19

1 answer

0

Without getting into the merits of the solution

declare
    vn_qtd number;
    ...
    begin
      SELECT count(*)
      into vn_qtd
      FROM DBA_CONSTRAINTS 
      WHERE CONSTRAINT_NAME = 'UK_t127pwh154arjh5whq0g4dlrm';
      if vn_qtd = 0 then
        execute_immediate ('alter table FINALIDADE_OPERACAO_MODAL ' ||
                           ' add constraint UK_t127pwh154arjh5whq0g4dlrm unique (NOME)');
      end if;
end;
    
26.09.2016 / 23:09