
/*------ ATD 272183 ------*/
-- Adicionando coluna NUMORD na tabela REFERENCIANFCOMPLEMENTAR
DECLARE v_count NUMBER(1) := 0; 
BEGIN 
SELECT 1 INTO v_count FROM USER_TAB_COLUMNS WHERE Upper(table_name) = 'REFERENCIANFCOMPLEMENTAR' AND Upper(column_name) = 'NUMORDNFENTRA'; 
EXCEPTION 
WHEN NO_DATA_FOUND THEN 
EXECUTE IMMEDIATE 'ALTER TABLE REFERENCIANFCOMPLEMENTAR ADD NUMORDNFENTRA INTEGER default 0 not null '; 
END;
DECLARE v_count NUMBER:=0;
BEGIN
  SELECT 1 INTO v_count FROM USER_TAB_COLUMNS WHERE UPPER(table_name) = 'DADOSNOTANFE' AND UPPER(column_name) = 'IDDEST';
  EXCEPTION
  WHEN NO_DATA_FOUND THEN
  begin
    EXECUTE IMMEDIATE 'ALTER TABLE DADOSNOTANFE ADD IDDEST INTEGER DEFAULT 1 ';
	EXECUTE IMMEDIATE 'ALTER TABLE DADOSNOTANFE ADD INDFINAL INTEGER DEFAULT 0';
	EXECUTE IMMEDIATE 'ALTER TABLE DADOSNOTANFE ADD INDPRES INTEGER  DEFAULT 1';
	EXECUTE IMMEDIATE 'ALTER TABLE DADOSNOTANFE ADD IDESTRANGEIRO VARCHAR(20) DEFAULT '''' ';
	EXECUTE IMMEDIATE 'ALTER TABLE DADOSNOTANFE ADD INDIEDEST INTEGER  ';
  end;
END;
/

CREATE OR REPLACE TRIGGER COMPLEMENTONFSAIDA_I	AFTER INSERT	ON  COMPLEMENTONFSAIDA FOR EACH ROW
BEGIN
	UPDATE COMPLEMENTONFSAIDA SET DTEMIS = SYSDATE where NUMORD = :new.NUMORD; 
END;


/
MERGE into dadoadicional using dual on (oid = 37387) when not matched then
insert ( RCLASSECONCRETA,RAPLICATIVO,RDOMINIO,RLISTA,RTIPO,RITEM,RESTRICAO,VISIVEL,MASCARA,PADRAO,MAXIMO,MINIMO,VALOR,OID) values (7,7    ,7,7,1013,44,0,0,'','',1,0,'Identificador estrangeiro',37387);