alter table parametros add par_copiarcliente varchar(200); update parametros set par_copiarcliente = encode(convert_to(par_cliente, 'latin1'), 'base64'); insert into atualizacoes(atu_nome) values ('v18020001_240118.sql'); alter table exportaintegracaohospital alter eih_codigo type bigint; insert into atualizacoes(atu_nome) values ('v18020002_160218.sql'); create sequence motivorecoleta_sequence; select criasequencia('motivorecoleta'); alter table parametros add par_copiamotivorecoleta varchar(200); alter table examerequisicao add mrc_codigo integer; create index xif426examerequisicao on examerequisicao ( fil_codigo, mrc_codigo ); create table motivorecoleta ( fil_codigo integer not null, mrc_codigo integer not null, mrc_descricao varchar(100), mrc_exigirjustificativa boolean ); create unique index xpkmotivorecoleta on motivorecoleta ( fil_codigo, mrc_codigo ); create index xif1motivorecoleta on motivorecoleta ( fil_codigo ); alter table motivorecoleta add primary key (fil_codigo, mrc_codigo); drop function fn_td_examerequisicao() cascade; create function fn_td_examerequisicao() returns opaque as ' declare numrows integer; begin select count(*) into numrows from logids where logids.fil_codigo = old.fil_codigo and logids.exa_codigo = old.exa_codigo and logids.mco_codigo = old.mco_codigo and logids.req_codigo = old.req_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela logids.''; end if; delete from examerequisicaohistoricosetor where examerequisicaohistoricosetor.fil_codigo = old.fil_codigo and examerequisicaohistoricosetor.exa_codigo = old.exa_codigo and examerequisicaohistoricosetor.mco_codigo = old.mco_codigo and examerequisicaohistoricosetor.req_codigo = old.req_codigo; delete from examerequisicaoetiquetas where examerequisicaoetiquetas.fil_codigo = old.fil_codigo and examerequisicaoetiquetas.exa_codigo = old.exa_codigo and examerequisicaoetiquetas.mco_codigo = old.mco_codigo and examerequisicaoetiquetas.req_codigo = old.req_codigo; delete from examerequisicaoemailatraso where examerequisicaoemailatraso.fil_codigo = old.fil_codigo and examerequisicaoemailatraso.exa_codigo = old.exa_codigo and examerequisicaoemailatraso.mco_codigo = old.mco_codigo and examerequisicaoemailatraso.req_codigo = old.req_codigo; select count(*) into numrows from examerequisicaodadosbrutos where examerequisicaodadosbrutos.fil_codigo = old.fil_codigo and examerequisicaodadosbrutos.exa_codigo = old.exa_codigo and examerequisicaodadosbrutos.mco_codigo = old.mco_codigo and examerequisicaodadosbrutos.req_codigo = old.req_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicaodadosbrutos.''; end if; delete from examerequisicaoincerteza where examerequisicaoincerteza.fil_codigo = old.fil_codigo and examerequisicaoincerteza.exa_codigo = old.exa_codigo and examerequisicaoincerteza.mco_codigo = old.mco_codigo and examerequisicaoincerteza.req_codigo = old.req_codigo; select count(*) into numrows from lotefilialexamerequisicao where lotefilialexamerequisicao.fil_codigo = old.fil_codigo and lotefilialexamerequisicao.exa_codigo = old.exa_codigo and lotefilialexamerequisicao.mco_codigo = old.mco_codigo and lotefilialexamerequisicao.req_codigo = old.req_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela lotefilialexamerequisicao.''; end if; delete from examerequisicaoresultado where examerequisicaoresultado.fil_codigo = old.fil_codigo and examerequisicaoresultado.exa_codigo = old.exa_codigo and examerequisicaoresultado.mco_codigo = old.mco_codigo and examerequisicaoresultado.req_codigo = old.req_codigo; select count(*) into numrows from examerequisicaolaminas where examerequisicaolaminas.fil_codigo = old.fil_codigo and examerequisicaolaminas.exa_codigo = old.exa_codigo and examerequisicaolaminas.mco_codigo = old.mco_codigo and examerequisicaolaminas.req_codigo = old.req_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicaolaminas.''; end if; select count(*) into numrows from examerequisicaohash where examerequisicaohash.fil_codigo = old.fil_codigo and examerequisicaohash.exa_codigo = old.exa_codigo and examerequisicaohash.mco_codigo = old.mco_codigo and examerequisicaohash.req_codigo = old.req_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicaohash.''; end if; delete from examerequisicaotrocas where examerequisicaotrocas.fil_codigo = old.fil_codigo and examerequisicaotrocas.exa_codigo = old.exa_codigo and examerequisicaotrocas.mco_codigo = old.mco_codigo and examerequisicaotrocas.req_codigo = old.req_codigo; delete from examerequisicaohistoricolaudo where examerequisicaohistoricolaudo.fil_codigo = old.fil_codigo and examerequisicaohistoricolaudo.exa_codigo = old.exa_codigo and examerequisicaohistoricolaudo.mco_codigo = old.mco_codigo and examerequisicaohistoricolaudo.req_codigo = old.req_codigo; delete from examerequisicaosetor where examerequisicaosetor.fil_codigo = old.fil_codigo and examerequisicaosetor.exa_codigo = old.exa_codigo and examerequisicaosetor.mco_codigo = old.mco_codigo and examerequisicaosetor.req_codigo = old.req_codigo; select count(*) into numrows from examerequisicaoguiaagrupada where examerequisicaoguiaagrupada.fil_codigo = old.fil_codigo and examerequisicaoguiaagrupada.exa_codigo = old.exa_codigo and examerequisicaoguiaagrupada.mco_codigo = old.mco_codigo and examerequisicaoguiaagrupada.req_codigo = old.req_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicaoguiaagrupada.''; end if; delete from examerequisicaosituacoes where examerequisicaosituacoes.fil_codigo = old.fil_codigo and examerequisicaosituacoes.exa_codigo = old.exa_codigo and examerequisicaosituacoes.mco_codigo = old.mco_codigo and examerequisicaosituacoes.req_codigo = old.req_codigo; select count(*) into numrows from loteexternoexamerequisicao where loteexternoexamerequisicao.fil_kodigo = old.fil_codigo and loteexternoexamerequisicao.exa_codigo = old.exa_codigo and loteexternoexamerequisicao.mco_codigo = old.mco_codigo and loteexternoexamerequisicao.req_codigo = old.req_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela loteexternoexamerequisicao.''; end if; delete from examerequisicaorecipiente where examerequisicaorecipiente.fil_codigo = old.fil_codigo and examerequisicaorecipiente.exa_codigo = old.exa_codigo and examerequisicaorecipiente.mco_codigo = old.mco_codigo and examerequisicaorecipiente.req_codigo = old.req_codigo; select count(*) into numrows from faturaexamerequisicao where faturaexamerequisicao.fil_kodigo = old.fil_codigo and faturaexamerequisicao.exa_codigo = old.exa_codigo and faturaexamerequisicao.mco_codigo = old.mco_codigo and faturaexamerequisicao.req_codigo = old.req_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela faturaexamerequisicao.''; end if; delete from interfaceexamerequisicao where interfaceexamerequisicao.fil_codigo = old.fil_codigo and interfaceexamerequisicao.exa_codigo = old.exa_codigo and interfaceexamerequisicao.mco_codigo = old.mco_codigo and interfaceexamerequisicao.req_codigo = old.req_codigo; delete from materialexamerequis where materialexamerequis.fil_codigo = old.fil_codigo and materialexamerequis.exa_codigo = old.exa_codigo and materialexamerequis.mco_codigo = old.mco_codigo and materialexamerequis.req_codigo = old.req_codigo; delete from examerequisicaoresultado where fil_codigo = old.fil_codigo and req_codigo = old.req_codigo and exa_codigo = old.exa_codigo and mco_codigo = old.mco_codigo; return old; end' language 'plpgsql'; create trigger td_examerequisicao after delete on examerequisicao for each row execute procedure fn_td_examerequisicao(); drop function fn_ti_examerequisicao() cascade; create function fn_ti_examerequisicao() returns opaque as ' declare numrows integer; tmp varchar; begin select count(*) into numrows from motivorecoleta where new.fil_codigo = motivorecoleta.fil_codigo and new.mrc_codigo = motivorecoleta.mrc_codigo; tmp:=''motivorecoleta|''; tmp:=tmp || ''fil_codigo='' || new.fil_codigo || ''|''; tmp:=tmp || ''mrc_codigo='' || new.mrc_codigo || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.fil_codigo is not null and new.mrc_codigo is not null and numrows = 0 ) then raise exception ''o registro nao pode ser inserido, pois um valor informado nao existe na tabela motivorecoleta. chave para consulta:[%]'',tmp using errcode=upper(''ifkne''); end if; select count(*) into numrows from usuario where new.usr_codduplaconferencia = usuario.usr_codigo; tmp:=''usuario|''; tmp:=tmp || ''usr_codigo='' || new.usr_codduplaconferencia || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.usr_codduplaconferencia is not null and numrows = 0 ) then raise exception ''o registro nao pode ser inserido, pois um valor informado nao existe na tabela usuario. chave para consulta:[%]'',tmp using errcode=upper(''ifkne''); end if; select count(*) into numrows from usuario where new.usr_codsolicitadotiss = usuario.usr_codigo; tmp:=''usuario|''; tmp:=tmp || ''usr_codigo='' || new.usr_codsolicitadotiss || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.usr_codsolicitadotiss is not null and numrows = 0 ) then raise exception ''o registro nao pode ser inserido, pois um valor informado nao existe na tabela usuario. chave para consulta:[%]'',tmp using errcode=upper(''ifkne''); end if; select count(*) into numrows from examematcoleta where new.fil_codigo = examematcoleta.fil_codigo and new.exa_codigopai = examematcoleta.exa_codigo and new.mco_codigopai = examematcoleta.mco_codigo; tmp:=''examematcoleta|''; tmp:=tmp || ''fil_codigo='' || new.fil_codigo || ''|''; tmp:=tmp || ''exa_codigo='' || new.exa_codigopai || ''|''; tmp:=tmp || ''mco_codigo='' || new.mco_codigopai || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.fil_codigo is not null and new.exa_codigopai is not null and new.mco_codigopai is not null and numrows = 0 ) then raise exception ''o registro nao pode ser inserido, pois um valor informado nao existe na tabela examematcoleta. chave para consulta:[%]'',tmp using errcode=upper(''ifkne''); end if; select count(*) into numrows from usuario where new.usr_codcoletar = usuario.usr_codigo; tmp:=''usuario|''; tmp:=tmp || ''usr_codigo='' || new.usr_codcoletar || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.usr_codcoletar is not null and numrows = 0 ) then raise exception ''o registro nao pode ser inserido, pois um valor informado nao existe na tabela usuario. chave para consulta:[%]'',tmp using errcode=upper(''ifkne''); end if; select count(*) into numrows from usuario where new.usr_codtransportechegada = usuario.usr_codigo; tmp:=''usuario|''; tmp:=tmp || ''usr_codigo='' || new.usr_codtransportechegada || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.usr_codtransportechegada is not null and numrows = 0 ) then raise exception ''o registro nao pode ser inserido, pois um valor informado nao existe na tabela usuario. chave para consulta:[%]'',tmp using errcode=upper(''ifkne''); end if; select count(*) into numrows from usuario where new.usr_codtransportesaida = usuario.usr_codigo; tmp:=''usuario|''; tmp:=tmp || ''usr_codigo='' || new.usr_codtransportesaida || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.usr_codtransportesaida is not null and numrows = 0 ) then raise exception ''o registro nao pode ser inserido, pois um valor informado nao existe na tabela usuario. chave para consulta:[%]'',tmp using errcode=upper(''ifkne''); end if; select count(*) into numrows from usuario where new.usr_codtrocalayout = usuario.usr_codigo; tmp:=''usuario|''; tmp:=tmp || ''usr_codigo='' || new.usr_codtrocalayout || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.usr_codtrocalayout is not null and numrows = 0 ) then raise exception ''o registro nao pode ser inserido, pois um valor informado nao existe na tabela usuario. chave para consulta:[%]'',tmp using errcode=upper(''ifkne''); end if; select count(*) into numrows from usuario where new.usr_codalteracaopreco = usuario.usr_codigo; tmp:=''usuario|''; tmp:=tmp || ''usr_codigo='' || new.usr_codalteracaopreco || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.usr_codalteracaopreco is not null and numrows = 0 ) then raise exception ''o registro nao pode ser inserido, pois um valor informado nao existe na tabela usuario. chave para consulta:[%]'',tmp using errcode=upper(''ifkne''); end if; select count(*) into numrows from usuario where new.usr_codrecoleta = usuario.usr_codigo; tmp:=''usuario|''; tmp:=tmp || ''usr_codigo='' || new.usr_codrecoleta || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.usr_codrecoleta is not null and numrows = 0 ) then raise exception ''o registro nao pode ser inserido, pois um valor informado nao existe na tabela usuario. chave para consulta:[%]'',tmp using errcode=upper(''ifkne''); end if; select count(*) into numrows from usuario where new.usr_codfaturarepasse = usuario.usr_codigo; tmp:=''usuario|''; tmp:=tmp || ''usr_codigo='' || new.usr_codfaturarepasse || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.usr_codfaturarepasse is not null and numrows = 0 ) then raise exception ''o registro nao pode ser inserido, pois um valor informado nao existe na tabela usuario. chave para consulta:[%]'',tmp using errcode=upper(''ifkne''); end if; select count(*) into numrows from usuario where new.usr_codrepeticao = usuario.usr_codigo; tmp:=''usuario|''; tmp:=tmp || ''usr_codigo='' || new.usr_codrepeticao || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.usr_codrepeticao is not null and numrows = 0 ) then raise exception ''o registro nao pode ser inserido, pois um valor informado nao existe na tabela usuario. chave para consulta:[%]'',tmp using errcode=upper(''ifkne''); end if; select count(*) into numrows from usuario where new.usr_codguia = usuario.usr_codigo; tmp:=''usuario|''; tmp:=tmp || ''usr_codigo='' || new.usr_codguia || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.usr_codguia is not null and numrows = 0 ) then raise exception ''o registro nao pode ser inserido, pois um valor informado nao existe na tabela usuario. chave para consulta:[%]'',tmp using errcode=upper(''ifkne''); end if; select count(*) into numrows from usuario where new.usr_codexcluido = usuario.usr_codigo; tmp:=''usuario|''; tmp:=tmp || ''usr_codigo='' || new.usr_codexcluido || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.usr_codexcluido is not null and numrows = 0 ) then raise exception ''o registro nao pode ser inserido, pois um valor informado nao existe na tabela usuario. chave para consulta:[%]'',tmp using errcode=upper(''ifkne''); end if; select count(*) into numrows from usuario where new.usr_codmaterialsetor = usuario.usr_codigo; tmp:=''usuario|''; tmp:=tmp || ''usr_codigo='' || new.usr_codmaterialsetor || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.usr_codmaterialsetor is not null and numrows = 0 ) then raise exception ''o registro nao pode ser inserido, pois um valor informado nao existe na tabela usuario. chave para consulta:[%]'',tmp using errcode=upper(''ifkne''); end if; select count(*) into numrows from usuario where new.usr_codloteexterno = usuario.usr_codigo; tmp:=''usuario|''; tmp:=tmp || ''usr_codigo='' || new.usr_codloteexterno || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.usr_codloteexterno is not null and numrows = 0 ) then raise exception ''o registro nao pode ser inserido, pois um valor informado nao existe na tabela usuario. chave para consulta:[%]'',tmp using errcode=upper(''ifkne''); end if; select count(*) into numrows from usuario where new.usr_codetqtriagem = usuario.usr_codigo; tmp:=''usuario|''; tmp:=tmp || ''usr_codigo='' || new.usr_codetqtriagem || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.usr_codetqtriagem is not null and numrows = 0 ) then raise exception ''o registro nao pode ser inserido, pois um valor informado nao existe na tabela usuario. chave para consulta:[%]'',tmp using errcode=upper(''ifkne''); end if; select count(*) into numrows from usuario where new.usr_codetqcoleta = usuario.usr_codigo; tmp:=''usuario|''; tmp:=tmp || ''usr_codigo='' || new.usr_codetqcoleta || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.usr_codetqcoleta is not null and numrows = 0 ) then raise exception ''o registro nao pode ser inserido, pois um valor informado nao existe na tabela usuario. chave para consulta:[%]'',tmp using errcode=upper(''ifkne''); end if; select count(*) into numrows from usuario where new.usr_codtriagem = usuario.usr_codigo; tmp:=''usuario|''; tmp:=tmp || ''usr_codigo='' || new.usr_codtriagem || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.usr_codtriagem is not null and numrows = 0 ) then raise exception ''o registro nao pode ser inserido, pois um valor informado nao existe na tabela usuario. chave para consulta:[%]'',tmp using errcode=upper(''ifkne''); end if; select count(*) into numrows from usuario where new.usr_codnaofaturar = usuario.usr_codigo; tmp:=''usuario|''; tmp:=tmp || ''usr_codigo='' || new.usr_codnaofaturar || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.usr_codnaofaturar is not null and numrows = 0 ) then raise exception ''o registro nao pode ser inserido, pois um valor informado nao existe na tabela usuario. chave para consulta:[%]'',tmp using errcode=upper(''ifkne''); end if; select count(*) into numrows from usuario where new.usr_codcortesia = usuario.usr_codigo; tmp:=''usuario|''; tmp:=tmp || ''usr_codigo='' || new.usr_codcortesia || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.usr_codcortesia is not null and numrows = 0 ) then raise exception ''o registro nao pode ser inserido, pois um valor informado nao existe na tabela usuario. chave para consulta:[%]'',tmp using errcode=upper(''ifkne''); end if; select count(*) into numrows from usuario where new.usr_codmapa = usuario.usr_codigo; tmp:=''usuario|''; tmp:=tmp || ''usr_codigo='' || new.usr_codmapa || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.usr_codmapa is not null and numrows = 0 ) then raise exception ''o registro nao pode ser inserido, pois um valor informado nao existe na tabela usuario. chave para consulta:[%]'',tmp using errcode=upper(''ifkne''); end if; select count(*) into numrows from usuario where new.usr_codigo = usuario.usr_codigo; tmp:=''usuario|''; tmp:=tmp || ''usr_codigo='' || new.usr_codigo || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.usr_codigo is not null and numrows = 0 ) then raise exception ''o registro nao pode ser inserido, pois um valor informado nao existe na tabela usuario. chave para consulta:[%]'',tmp using errcode=upper(''ifkne''); end if; select count(*) into numrows from examematcoleta where new.fil_codigo = examematcoleta.fil_codigo and new.exa_codigo = examematcoleta.exa_codigo and new.mco_codigo = examematcoleta.mco_codigo; tmp:=''examematcoleta|''; tmp:=tmp || ''fil_codigo='' || new.fil_codigo || ''|''; tmp:=tmp || ''exa_codigo='' || new.exa_codigo || ''|''; tmp:=tmp || ''mco_codigo='' || new.mco_codigo || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( numrows = 0 ) then raise exception ''o registro nao pode ser inserido, pois um valor informado nao existe na tabela examematcoleta. chave para consulta:[%]'',tmp using errcode=upper(''ifkne''); end if; select count(*) into numrows from usuario where new.usr_codimpressao = usuario.usr_codigo; tmp:=''usuario|''; tmp:=tmp || ''usr_codigo='' || new.usr_codimpressao || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.usr_codimpressao is not null and numrows = 0 ) then raise exception ''o registro nao pode ser inserido, pois um valor informado nao existe na tabela usuario. chave para consulta:[%]'',tmp using errcode=upper(''ifkne''); end if; select count(*) into numrows from usuario where new.usr_codentrega = usuario.usr_codigo; tmp:=''usuario|''; tmp:=tmp || ''usr_codigo='' || new.usr_codentrega || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.usr_codentrega is not null and numrows = 0 ) then raise exception ''o registro nao pode ser inserido, pois um valor informado nao existe na tabela usuario. chave para consulta:[%]'',tmp using errcode=upper(''ifkne''); end if; select count(*) into numrows from usuario where new.usr_codfatura = usuario.usr_codigo; tmp:=''usuario|''; tmp:=tmp || ''usr_codigo='' || new.usr_codfatura || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.usr_codfatura is not null and numrows = 0 ) then raise exception ''o registro nao pode ser inserido, pois um valor informado nao existe na tabela usuario. chave para consulta:[%]'',tmp using errcode=upper(''ifkne''); end if; select count(*) into numrows from usuario where new.usr_codmaterial = usuario.usr_codigo; tmp:=''usuario|''; tmp:=tmp || ''usr_codigo='' || new.usr_codmaterial || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.usr_codmaterial is not null and numrows = 0 ) then raise exception ''o registro nao pode ser inserido, pois um valor informado nao existe na tabela usuario. chave para consulta:[%]'',tmp using errcode=upper(''ifkne''); end if; select count(*) into numrows from usuario where new.usr_coddigitador = usuario.usr_codigo; tmp:=''usuario|''; tmp:=tmp || ''usr_codigo='' || new.usr_coddigitador || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.usr_coddigitador is not null and numrows = 0 ) then raise exception ''o registro nao pode ser inserido, pois um valor informado nao existe na tabela usuario. chave para consulta:[%]'',tmp using errcode=upper(''ifkne''); end if; select count(*) into numrows from usuario where new.usr_codassina = usuario.usr_codigo; tmp:=''usuario|''; tmp:=tmp || ''usr_codigo='' || new.usr_codassina || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.usr_codassina is not null and numrows = 0 ) then raise exception ''o registro nao pode ser inserido, pois um valor informado nao existe na tabela usuario. chave para consulta:[%]'',tmp using errcode=upper(''ifkne''); end if; select count(*) into numrows from materialcoleta where new.fil_codigo = materialcoleta.fil_codigo and new.mco_codigo = materialcoleta.mco_codigo; tmp:=''materialcoleta|''; tmp:=tmp || ''fil_codigo='' || new.fil_codigo || ''|''; tmp:=tmp || ''mco_codigo='' || new.mco_codigo || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.fil_codigo is not null and new.mco_codigo is not null and numrows = 0 ) then raise exception ''o registro nao pode ser inserido, pois um valor informado nao existe na tabela materialcoleta. chave para consulta:[%]'',tmp using errcode=upper(''ifkne''); end if; select count(*) into numrows from metodologia where new.fil_codigo = metodologia.fil_codigo and new.met_codigo = metodologia.met_codigo; tmp:=''metodologia|''; tmp:=tmp || ''fil_codigo='' || new.fil_codigo || ''|''; tmp:=tmp || ''met_codigo='' || new.met_codigo || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.fil_codigo is not null and new.met_codigo is not null and numrows = 0 ) then raise exception ''o registro nao pode ser inserido, pois um valor informado nao existe na tabela metodologia. chave para consulta:[%]'',tmp using errcode=upper(''ifkne''); end if; select count(*) into numrows from requisicao where new.fil_codigo = requisicao.fil_codigo and new.req_codigo = requisicao.req_codigo; tmp:=''requisicao|''; tmp:=tmp || ''fil_codigo='' || new.fil_codigo || ''|''; tmp:=tmp || ''req_codigo='' || new.req_codigo || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( numrows = 0 ) then raise exception ''o registro nao pode ser inserido, pois um valor informado nao existe na tabela requisicao. chave para consulta:[%]'',tmp using errcode=upper(''ifkne''); end if; insert into examerequisicaoresultado(fil_codigo, req_codigo, exa_codigo, mco_codigo, ert_resultado) values (new.fil_codigo, new.req_codigo, new.exa_codigo, new.mco_codigo, new.exr_resultado); /* troca o valor do campo de resultado na tabela exame requisicao */ new.exr_resultado = ''.''; return new; end' language 'plpgsql'; create trigger ti_examerequisicao after insert on examerequisicao for each row execute procedure fn_ti_examerequisicao(); drop function fn_tu_b_examerequisicao() cascade; create function fn_tu_b_examerequisicao() returns opaque as ' declare req bigint; begin select req_codigo into req from examerequisicaoresultado where fil_codigo = new.fil_codigo and req_codigo = new.req_codigo and exa_codigo = new.exa_codigo and mco_codigo = new.mco_codigo; if (not found) then insert into examerequisicaoresultado(fil_codigo, req_codigo, exa_codigo, mco_codigo) values (new.fil_codigo, new.req_codigo, new.exa_codigo, new.mco_codigo); end if; if ((upper(new.exr_situacao) = upper(''l'') or upper(new.exr_situacao) = upper(''c'') or upper(new.exr_situacao) = upper(''i'') or upper(new.exr_situacao) = upper(''e'') or upper(new.exr_situacao) = upper(''p'')) and new.exr_resultado is not null and length(new.exr_resultado) > 0) then update examerequisicaoresultado set ert_resultado = new.exr_resultado where fil_codigo = new.fil_codigo and req_codigo = new.req_codigo and exa_codigo = new.exa_codigo and mco_codigo = new.mco_codigo; end if; if ((new.exr_situacao is null or new.exr_situacao = '''' or upper(new.exr_situacao) = upper(''f'') or upper(new.exr_situacao) = upper(''t'') or upper(new.exr_situacao) = upper(''r''))) then update examerequisicaoresultado set ert_resultado = new.exr_resultado where fil_codigo = new.fil_codigo and req_codigo = new.req_codigo and exa_codigo = new.exa_codigo and mco_codigo = new.mco_codigo; end if; /* troca o valor do campo de resultado na tabela exame requisicao */ new.exr_resultado := null; return new; end' language 'plpgsql'; create trigger tu_b_examerequisicao before update on examerequisicao for each row execute procedure fn_tu_b_examerequisicao(); drop function fn_tu_examerequisicao() cascade; create function fn_tu_examerequisicao() returns opaque as ' declare numrows integer; tmp varchar; begin select count(*) into numrows from motivorecoleta where new.fil_codigo = motivorecoleta.fil_codigo and new.mrc_codigo = motivorecoleta.mrc_codigo; tmp:=''motivorecoleta|''; tmp:=tmp || ''fil_codigo='' || new.fil_codigo || ''|''; tmp:=tmp || ''mrc_codigo='' || new.mrc_codigo || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.fil_codigo is not null and new.mrc_codigo is not null and numrows = 0 ) then raise exception ''o registro nao pode ser alterado, pois um valor nao existe na tabela motivorecoleta. chave para consulta:[%]'',tmp using errcode=upper(''ufkne''); end if; select count(*) into numrows from usuario where new.usr_codduplaconferencia = usuario.usr_codigo; tmp:=''usuario|''; tmp:=tmp || ''usr_codigo='' || new.usr_codduplaconferencia || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.usr_codduplaconferencia is not null and numrows = 0 ) then raise exception ''o registro nao pode ser alterado, pois um valor nao existe na tabela usuario. chave para consulta:[%]'',tmp using errcode=upper(''ufkne''); end if; select count(*) into numrows from usuario where new.usr_codsolicitadotiss = usuario.usr_codigo; tmp:=''usuario|''; tmp:=tmp || ''usr_codigo='' || new.usr_codsolicitadotiss || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.usr_codsolicitadotiss is not null and numrows = 0 ) then raise exception ''o registro nao pode ser alterado, pois um valor nao existe na tabela usuario. chave para consulta:[%]'',tmp using errcode=upper(''ufkne''); end if; select count(*) into numrows from examematcoleta where new.fil_codigo = examematcoleta.fil_codigo and new.exa_codigopai = examematcoleta.exa_codigo and new.mco_codigopai = examematcoleta.mco_codigo; tmp:=''examematcoleta|''; tmp:=tmp || ''fil_codigo='' || new.fil_codigo || ''|''; tmp:=tmp || ''exa_codigo='' || new.exa_codigopai || ''|''; tmp:=tmp || ''mco_codigo='' || new.mco_codigopai || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.fil_codigo is not null and new.exa_codigopai is not null and new.mco_codigopai is not null and numrows = 0 ) then raise exception ''o registro nao pode ser alterado, pois um valor nao existe na tabela examematcoleta. chave para consulta:[%]'',tmp using errcode=upper(''ufkne''); end if; select count(*) into numrows from usuario where new.usr_codcoletar = usuario.usr_codigo; tmp:=''usuario|''; tmp:=tmp || ''usr_codigo='' || new.usr_codcoletar || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.usr_codcoletar is not null and numrows = 0 ) then raise exception ''o registro nao pode ser alterado, pois um valor nao existe na tabela usuario. chave para consulta:[%]'',tmp using errcode=upper(''ufkne''); end if; select count(*) into numrows from usuario where new.usr_codtransportechegada = usuario.usr_codigo; tmp:=''usuario|''; tmp:=tmp || ''usr_codigo='' || new.usr_codtransportechegada || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.usr_codtransportechegada is not null and numrows = 0 ) then raise exception ''o registro nao pode ser alterado, pois um valor nao existe na tabela usuario. chave para consulta:[%]'',tmp using errcode=upper(''ufkne''); end if; select count(*) into numrows from usuario where new.usr_codtransportesaida = usuario.usr_codigo; tmp:=''usuario|''; tmp:=tmp || ''usr_codigo='' || new.usr_codtransportesaida || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.usr_codtransportesaida is not null and numrows = 0 ) then raise exception ''o registro nao pode ser alterado, pois um valor nao existe na tabela usuario. chave para consulta:[%]'',tmp using errcode=upper(''ufkne''); end if; select count(*) into numrows from usuario where new.usr_codtrocalayout = usuario.usr_codigo; tmp:=''usuario|''; tmp:=tmp || ''usr_codigo='' || new.usr_codtrocalayout || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.usr_codtrocalayout is not null and numrows = 0 ) then raise exception ''o registro nao pode ser alterado, pois um valor nao existe na tabela usuario. chave para consulta:[%]'',tmp using errcode=upper(''ufkne''); end if; select count(*) into numrows from usuario where new.usr_codalteracaopreco = usuario.usr_codigo; tmp:=''usuario|''; tmp:=tmp || ''usr_codigo='' || new.usr_codalteracaopreco || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.usr_codalteracaopreco is not null and numrows = 0 ) then raise exception ''o registro nao pode ser alterado, pois um valor nao existe na tabela usuario. chave para consulta:[%]'',tmp using errcode=upper(''ufkne''); end if; select count(*) into numrows from usuario where new.usr_codrecoleta = usuario.usr_codigo; tmp:=''usuario|''; tmp:=tmp || ''usr_codigo='' || new.usr_codrecoleta || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.usr_codrecoleta is not null and numrows = 0 ) then raise exception ''o registro nao pode ser alterado, pois um valor nao existe na tabela usuario. chave para consulta:[%]'',tmp using errcode=upper(''ufkne''); end if; select count(*) into numrows from usuario where new.usr_codfaturarepasse = usuario.usr_codigo; tmp:=''usuario|''; tmp:=tmp || ''usr_codigo='' || new.usr_codfaturarepasse || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.usr_codfaturarepasse is not null and numrows = 0 ) then raise exception ''o registro nao pode ser alterado, pois um valor nao existe na tabela usuario. chave para consulta:[%]'',tmp using errcode=upper(''ufkne''); end if; select count(*) into numrows from usuario where new.usr_codrepeticao = usuario.usr_codigo; tmp:=''usuario|''; tmp:=tmp || ''usr_codigo='' || new.usr_codrepeticao || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.usr_codrepeticao is not null and numrows = 0 ) then raise exception ''o registro nao pode ser alterado, pois um valor nao existe na tabela usuario. chave para consulta:[%]'',tmp using errcode=upper(''ufkne''); end if; select count(*) into numrows from usuario where new.usr_codguia = usuario.usr_codigo; tmp:=''usuario|''; tmp:=tmp || ''usr_codigo='' || new.usr_codguia || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.usr_codguia is not null and numrows = 0 ) then raise exception ''o registro nao pode ser alterado, pois um valor nao existe na tabela usuario. chave para consulta:[%]'',tmp using errcode=upper(''ufkne''); end if; select count(*) into numrows from usuario where new.usr_codexcluido = usuario.usr_codigo; tmp:=''usuario|''; tmp:=tmp || ''usr_codigo='' || new.usr_codexcluido || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.usr_codexcluido is not null and numrows = 0 ) then raise exception ''o registro nao pode ser alterado, pois um valor nao existe na tabela usuario. chave para consulta:[%]'',tmp using errcode=upper(''ufkne''); end if; select count(*) into numrows from usuario where new.usr_codmaterialsetor = usuario.usr_codigo; tmp:=''usuario|''; tmp:=tmp || ''usr_codigo='' || new.usr_codmaterialsetor || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.usr_codmaterialsetor is not null and numrows = 0 ) then raise exception ''o registro nao pode ser alterado, pois um valor nao existe na tabela usuario. chave para consulta:[%]'',tmp using errcode=upper(''ufkne''); end if; select count(*) into numrows from usuario where new.usr_codloteexterno = usuario.usr_codigo; tmp:=''usuario|''; tmp:=tmp || ''usr_codigo='' || new.usr_codloteexterno || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.usr_codloteexterno is not null and numrows = 0 ) then raise exception ''o registro nao pode ser alterado, pois um valor nao existe na tabela usuario. chave para consulta:[%]'',tmp using errcode=upper(''ufkne''); end if; select count(*) into numrows from usuario where new.usr_codetqtriagem = usuario.usr_codigo; tmp:=''usuario|''; tmp:=tmp || ''usr_codigo='' || new.usr_codetqtriagem || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.usr_codetqtriagem is not null and numrows = 0 ) then raise exception ''o registro nao pode ser alterado, pois um valor nao existe na tabela usuario. chave para consulta:[%]'',tmp using errcode=upper(''ufkne''); end if; select count(*) into numrows from usuario where new.usr_codetqcoleta = usuario.usr_codigo; tmp:=''usuario|''; tmp:=tmp || ''usr_codigo='' || new.usr_codetqcoleta || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.usr_codetqcoleta is not null and numrows = 0 ) then raise exception ''o registro nao pode ser alterado, pois um valor nao existe na tabela usuario. chave para consulta:[%]'',tmp using errcode=upper(''ufkne''); end if; select count(*) into numrows from usuario where new.usr_codtriagem = usuario.usr_codigo; tmp:=''usuario|''; tmp:=tmp || ''usr_codigo='' || new.usr_codtriagem || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.usr_codtriagem is not null and numrows = 0 ) then raise exception ''o registro nao pode ser alterado, pois um valor nao existe na tabela usuario. chave para consulta:[%]'',tmp using errcode=upper(''ufkne''); end if; select count(*) into numrows from usuario where new.usr_codnaofaturar = usuario.usr_codigo; tmp:=''usuario|''; tmp:=tmp || ''usr_codigo='' || new.usr_codnaofaturar || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.usr_codnaofaturar is not null and numrows = 0 ) then raise exception ''o registro nao pode ser alterado, pois um valor nao existe na tabela usuario. chave para consulta:[%]'',tmp using errcode=upper(''ufkne''); end if; select count(*) into numrows from usuario where new.usr_codcortesia = usuario.usr_codigo; tmp:=''usuario|''; tmp:=tmp || ''usr_codigo='' || new.usr_codcortesia || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.usr_codcortesia is not null and numrows = 0 ) then raise exception ''o registro nao pode ser alterado, pois um valor nao existe na tabela usuario. chave para consulta:[%]'',tmp using errcode=upper(''ufkne''); end if; select count(*) into numrows from usuario where new.usr_codmapa = usuario.usr_codigo; tmp:=''usuario|''; tmp:=tmp || ''usr_codigo='' || new.usr_codmapa || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.usr_codmapa is not null and numrows = 0 ) then raise exception ''o registro nao pode ser alterado, pois um valor nao existe na tabela usuario. chave para consulta:[%]'',tmp using errcode=upper(''ufkne''); end if; select count(*) into numrows from usuario where new.usr_codigo = usuario.usr_codigo; tmp:=''usuario|''; tmp:=tmp || ''usr_codigo='' || new.usr_codigo || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.usr_codigo is not null and numrows = 0 ) then raise exception ''o registro nao pode ser alterado, pois um valor nao existe na tabela usuario. chave para consulta:[%]'',tmp using errcode=upper(''ufkne''); end if; select count(*) into numrows from examematcoleta where new.fil_codigo = examematcoleta.fil_codigo and new.exa_codigo = examematcoleta.exa_codigo and new.mco_codigo = examematcoleta.mco_codigo; tmp:=''examematcoleta|''; tmp:=tmp || ''fil_codigo='' || new.fil_codigo || ''|''; tmp:=tmp || ''exa_codigo='' || new.exa_codigo || ''|''; tmp:=tmp || ''mco_codigo='' || new.mco_codigo || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( numrows = 0 ) then raise exception ''o registro nao pode ser alterado, pois um valor nao existe na tabela examematcoleta. chave para consulta:[%]'',tmp using errcode=upper(''ufkne''); end if; select count(*) into numrows from usuario where new.usr_codimpressao = usuario.usr_codigo; tmp:=''usuario|''; tmp:=tmp || ''usr_codigo='' || new.usr_codimpressao || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.usr_codimpressao is not null and numrows = 0 ) then raise exception ''o registro nao pode ser alterado, pois um valor nao existe na tabela usuario. chave para consulta:[%]'',tmp using errcode=upper(''ufkne''); end if; select count(*) into numrows from usuario where new.usr_codentrega = usuario.usr_codigo; tmp:=''usuario|''; tmp:=tmp || ''usr_codigo='' || new.usr_codentrega || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.usr_codentrega is not null and numrows = 0 ) then raise exception ''o registro nao pode ser alterado, pois um valor nao existe na tabela usuario. chave para consulta:[%]'',tmp using errcode=upper(''ufkne''); end if; select count(*) into numrows from usuario where new.usr_codfatura = usuario.usr_codigo; tmp:=''usuario|''; tmp:=tmp || ''usr_codigo='' || new.usr_codfatura || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.usr_codfatura is not null and numrows = 0 ) then raise exception ''o registro nao pode ser alterado, pois um valor nao existe na tabela usuario. chave para consulta:[%]'',tmp using errcode=upper(''ufkne''); end if; select count(*) into numrows from usuario where new.usr_codmaterial = usuario.usr_codigo; tmp:=''usuario|''; tmp:=tmp || ''usr_codigo='' || new.usr_codmaterial || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.usr_codmaterial is not null and numrows = 0 ) then raise exception ''o registro nao pode ser alterado, pois um valor nao existe na tabela usuario. chave para consulta:[%]'',tmp using errcode=upper(''ufkne''); end if; select count(*) into numrows from usuario where new.usr_coddigitador = usuario.usr_codigo; tmp:=''usuario|''; tmp:=tmp || ''usr_codigo='' || new.usr_coddigitador || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.usr_coddigitador is not null and numrows = 0 ) then raise exception ''o registro nao pode ser alterado, pois um valor nao existe na tabela usuario. chave para consulta:[%]'',tmp using errcode=upper(''ufkne''); end if; select count(*) into numrows from usuario where new.usr_codassina = usuario.usr_codigo; tmp:=''usuario|''; tmp:=tmp || ''usr_codigo='' || new.usr_codassina || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.usr_codassina is not null and numrows = 0 ) then raise exception ''o registro nao pode ser alterado, pois um valor nao existe na tabela usuario. chave para consulta:[%]'',tmp using errcode=upper(''ufkne''); end if; select count(*) into numrows from materialcoleta where new.fil_codigo = materialcoleta.fil_codigo and new.mco_codigo = materialcoleta.mco_codigo; tmp:=''materialcoleta|''; tmp:=tmp || ''fil_codigo='' || new.fil_codigo || ''|''; tmp:=tmp || ''mco_codigo='' || new.mco_codigo || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.fil_codigo is not null and new.mco_codigo is not null and numrows = 0 ) then raise exception ''o registro nao pode ser alterado, pois um valor nao existe na tabela materialcoleta. chave para consulta:[%]'',tmp using errcode=upper(''ufkne''); end if; select count(*) into numrows from metodologia where new.fil_codigo = metodologia.fil_codigo and new.met_codigo = metodologia.met_codigo; tmp:=''metodologia|''; tmp:=tmp || ''fil_codigo='' || new.fil_codigo || ''|''; tmp:=tmp || ''met_codigo='' || new.met_codigo || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.fil_codigo is not null and new.met_codigo is not null and numrows = 0 ) then raise exception ''o registro nao pode ser alterado, pois um valor nao existe na tabela metodologia. chave para consulta:[%]'',tmp using errcode=upper(''ufkne''); end if; select count(*) into numrows from requisicao where new.fil_codigo = requisicao.fil_codigo and new.req_codigo = requisicao.req_codigo; tmp:=''requisicao|''; tmp:=tmp || ''fil_codigo='' || new.fil_codigo || ''|''; tmp:=tmp || ''req_codigo='' || new.req_codigo || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( numrows = 0 ) then raise exception ''o registro nao pode ser alterado, pois um valor nao existe na tabela requisicao. chave para consulta:[%]'',tmp using errcode=upper(''ufkne''); end if; if (old.fil_codigo <> new.fil_codigo or old.exa_codigo <> new.exa_codigo or old.mco_codigo <> new.mco_codigo or old.req_codigo <> new.req_codigo) then select count(*) from logids where logids.fil_codigo = old.fil_codigo and logids.exa_codigo = old.exa_codigo and logids.mco_codigo = old.mco_codigo and logids.req_codigo = old.req_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela logids.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.exa_codigo <> new.exa_codigo or old.mco_codigo <> new.mco_codigo or old.req_codigo <> new.req_codigo) then select count(*) from examerequisicaohistoricosetor where examerequisicaohistoricosetor.fil_codigo = old.fil_codigo and examerequisicaohistoricosetor.exa_codigo = old.exa_codigo and examerequisicaohistoricosetor.mco_codigo = old.mco_codigo and examerequisicaohistoricosetor.req_codigo = old.req_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicaohistoricosetor.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.exa_codigo <> new.exa_codigo or old.mco_codigo <> new.mco_codigo or old.req_codigo <> new.req_codigo) then select count(*) from examerequisicaoetiquetas where examerequisicaoetiquetas.fil_codigo = old.fil_codigo and examerequisicaoetiquetas.exa_codigo = old.exa_codigo and examerequisicaoetiquetas.mco_codigo = old.mco_codigo and examerequisicaoetiquetas.req_codigo = old.req_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicaoetiquetas.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.exa_codigo <> new.exa_codigo or old.mco_codigo <> new.mco_codigo or old.req_codigo <> new.req_codigo) then select count(*) from examerequisicaoemailatraso where examerequisicaoemailatraso.fil_codigo = old.fil_codigo and examerequisicaoemailatraso.exa_codigo = old.exa_codigo and examerequisicaoemailatraso.mco_codigo = old.mco_codigo and examerequisicaoemailatraso.req_codigo = old.req_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicaoemailatraso.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.exa_codigo <> new.exa_codigo or old.mco_codigo <> new.mco_codigo or old.req_codigo <> new.req_codigo) then select count(*) from examerequisicaodadosbrutos where examerequisicaodadosbrutos.fil_codigo = old.fil_codigo and examerequisicaodadosbrutos.exa_codigo = old.exa_codigo and examerequisicaodadosbrutos.mco_codigo = old.mco_codigo and examerequisicaodadosbrutos.req_codigo = old.req_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicaodadosbrutos.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.exa_codigo <> new.exa_codigo or old.mco_codigo <> new.mco_codigo or old.req_codigo <> new.req_codigo) then select count(*) from examerequisicaoincerteza where examerequisicaoincerteza.fil_codigo = old.fil_codigo and examerequisicaoincerteza.exa_codigo = old.exa_codigo and examerequisicaoincerteza.mco_codigo = old.mco_codigo and examerequisicaoincerteza.req_codigo = old.req_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicaoincerteza.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.exa_codigo <> new.exa_codigo or old.mco_codigo <> new.mco_codigo or old.req_codigo <> new.req_codigo) then select count(*) from lotefilialexamerequisicao where lotefilialexamerequisicao.fil_codigo = old.fil_codigo and lotefilialexamerequisicao.exa_codigo = old.exa_codigo and lotefilialexamerequisicao.mco_codigo = old.mco_codigo and lotefilialexamerequisicao.req_codigo = old.req_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela lotefilialexamerequisicao.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.exa_codigo <> new.exa_codigo or old.mco_codigo <> new.mco_codigo or old.req_codigo <> new.req_codigo) then select count(*) from examerequisicaoresultado where examerequisicaoresultado.fil_codigo = old.fil_codigo and examerequisicaoresultado.exa_codigo = old.exa_codigo and examerequisicaoresultado.mco_codigo = old.mco_codigo and examerequisicaoresultado.req_codigo = old.req_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicaoresultado.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.exa_codigo <> new.exa_codigo or old.mco_codigo <> new.mco_codigo or old.req_codigo <> new.req_codigo) then select count(*) from examerequisicaolaminas where examerequisicaolaminas.fil_codigo = old.fil_codigo and examerequisicaolaminas.exa_codigo = old.exa_codigo and examerequisicaolaminas.mco_codigo = old.mco_codigo and examerequisicaolaminas.req_codigo = old.req_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicaolaminas.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.exa_codigo <> new.exa_codigo or old.mco_codigo <> new.mco_codigo or old.req_codigo <> new.req_codigo) then select count(*) from examerequisicaohash where examerequisicaohash.fil_codigo = old.fil_codigo and examerequisicaohash.exa_codigo = old.exa_codigo and examerequisicaohash.mco_codigo = old.mco_codigo and examerequisicaohash.req_codigo = old.req_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicaohash.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.exa_codigo <> new.exa_codigo or old.mco_codigo <> new.mco_codigo or old.req_codigo <> new.req_codigo) then select count(*) from examerequisicaotrocas where examerequisicaotrocas.fil_codigo = old.fil_codigo and examerequisicaotrocas.exa_codigo = old.exa_codigo and examerequisicaotrocas.mco_codigo = old.mco_codigo and examerequisicaotrocas.req_codigo = old.req_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicaotrocas.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.exa_codigo <> new.exa_codigo or old.mco_codigo <> new.mco_codigo or old.req_codigo <> new.req_codigo) then select count(*) from examerequisicaohistoricolaudo where examerequisicaohistoricolaudo.fil_codigo = old.fil_codigo and examerequisicaohistoricolaudo.exa_codigo = old.exa_codigo and examerequisicaohistoricolaudo.mco_codigo = old.mco_codigo and examerequisicaohistoricolaudo.req_codigo = old.req_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicaohistoricolaudo.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.exa_codigo <> new.exa_codigo or old.mco_codigo <> new.mco_codigo or old.req_codigo <> new.req_codigo) then select count(*) from examerequisicaosetor where examerequisicaosetor.fil_codigo = old.fil_codigo and examerequisicaosetor.exa_codigo = old.exa_codigo and examerequisicaosetor.mco_codigo = old.mco_codigo and examerequisicaosetor.req_codigo = old.req_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicaosetor.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.exa_codigo <> new.exa_codigo or old.mco_codigo <> new.mco_codigo or old.req_codigo <> new.req_codigo) then select count(*) from examerequisicaoguiaagrupada where examerequisicaoguiaagrupada.fil_codigo = old.fil_codigo and examerequisicaoguiaagrupada.exa_codigo = old.exa_codigo and examerequisicaoguiaagrupada.mco_codigo = old.mco_codigo and examerequisicaoguiaagrupada.req_codigo = old.req_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicaoguiaagrupada.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.exa_codigo <> new.exa_codigo or old.mco_codigo <> new.mco_codigo or old.req_codigo <> new.req_codigo) then select count(*) from examerequisicaosituacoes where examerequisicaosituacoes.fil_codigo = old.fil_codigo and examerequisicaosituacoes.exa_codigo = old.exa_codigo and examerequisicaosituacoes.mco_codigo = old.mco_codigo and examerequisicaosituacoes.req_codigo = old.req_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicaosituacoes.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.exa_codigo <> new.exa_codigo or old.mco_codigo <> new.mco_codigo or old.req_codigo <> new.req_codigo) then select count(*) from loteexternoexamerequisicao where loteexternoexamerequisicao.fil_kodigo = old.fil_codigo and loteexternoexamerequisicao.exa_codigo = old.exa_codigo and loteexternoexamerequisicao.mco_codigo = old.mco_codigo and loteexternoexamerequisicao.req_codigo = old.req_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela loteexternoexamerequisicao.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.exa_codigo <> new.exa_codigo or old.mco_codigo <> new.mco_codigo or old.req_codigo <> new.req_codigo) then select count(*) from examerequisicaorecipiente where examerequisicaorecipiente.fil_codigo = old.fil_codigo and examerequisicaorecipiente.exa_codigo = old.exa_codigo and examerequisicaorecipiente.mco_codigo = old.mco_codigo and examerequisicaorecipiente.req_codigo = old.req_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicaorecipiente.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.exa_codigo <> new.exa_codigo or old.mco_codigo <> new.mco_codigo or old.req_codigo <> new.req_codigo) then select count(*) from faturaexamerequisicao where faturaexamerequisicao.fil_kodigo = old.fil_codigo and faturaexamerequisicao.exa_codigo = old.exa_codigo and faturaexamerequisicao.mco_codigo = old.mco_codigo and faturaexamerequisicao.req_codigo = old.req_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela faturaexamerequisicao.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.exa_codigo <> new.exa_codigo or old.mco_codigo <> new.mco_codigo or old.req_codigo <> new.req_codigo) then select count(*) from interfaceexamerequisicao where interfaceexamerequisicao.fil_codigo = old.fil_codigo and interfaceexamerequisicao.exa_codigo = old.exa_codigo and interfaceexamerequisicao.mco_codigo = old.mco_codigo and interfaceexamerequisicao.req_codigo = old.req_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela interfaceexamerequisicao.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.exa_codigo <> new.exa_codigo or old.mco_codigo <> new.mco_codigo or old.req_codigo <> new.req_codigo) then select count(*) from materialexamerequis where materialexamerequis.fil_codigo = old.fil_codigo and materialexamerequis.exa_codigo = old.exa_codigo and materialexamerequis.mco_codigo = old.mco_codigo and materialexamerequis.req_codigo = old.req_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela materialexamerequis.''; end if; end if; return new; end' language 'plpgsql'; create trigger tu_examerequisicao after update on examerequisicao for each row execute procedure fn_tu_examerequisicao(); drop function fn_td_filiais_postocoleta() cascade; create function fn_td_filiais_postocoleta() returns opaque as ' declare numrows integer; begin select count(*) into numrows from motivorecoleta where motivorecoleta.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela motivorecoleta.''; end if; delete from logvalidalote where logvalidalote.fil_codigo = old.fil_codigo; select count(*) into numrows from ambbpa where ambbpa.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela ambbpa.''; end if; select count(*) into numrows from categoriaprodutoalimentos where categoriaprodutoalimentos.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela categoriaprodutoalimentos.''; end if; delete from responsavelcertificado where responsavelcertificado.fil_codigo = old.fil_codigo; select count(*) into numrows from origemnaoconformidade where origemnaoconformidade.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela origemnaoconformidade.''; end if; select count(*) into numrows from filialemailaniversario where filialemailaniversario.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela filialemailaniversario.''; end if; select count(*) into numrows from filialsmsaniversario where filialsmsaniversario.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela filialsmsaniversario.''; end if; select count(*) into numrows from logemail where logemail.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela logemail.''; end if; delete from filialsmsresumo where filialsmsresumo.fil_codigo = old.fil_codigo; select count(*) into numrows from lanctocaixa where lanctocaixa.fil_codentrefilial = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela lanctocaixa.''; end if; select count(*) into numrows from lotefilial where lotefilial.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela lotefilial.''; end if; select count(*) into numrows from taxa where taxa.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela taxa.''; end if; select count(*) into numrows from logoffline where logoffline.fil_coddestino = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela logoffline.''; end if; select count(*) into numrows from logoffline where logoffline.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela logoffline.''; end if; select count(*) into numrows from pais where pais.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela pais.''; end if; select count(*) into numrows from logsms where logsms.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela logsms.''; end if; select count(*) into numrows from naoconformidade where naoconformidade.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela naoconformidade.''; end if; select count(*) into numrows from acaonaoconformidade where acaonaoconformidade.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela acaonaoconformidade.''; end if; select count(*) into numrows from procedencianaoconformidade where procedencianaoconformidade.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela procedencianaoconformidade.''; end if; select count(*) into numrows from banhomaria where banhomaria.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela banhomaria.''; end if; select count(*) into numrows from identificadorlamina where identificadorlamina.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela identificadorlamina.''; end if; select count(*) into numrows from materiallote where materiallote.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela materiallote.''; end if; select count(*) into numrows from examerequisicaohash where examerequisicaohash.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicaohash.''; end if; select count(*) into numrows from motivoalteracao where motivoalteracao.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela motivoalteracao.''; end if; select count(*) into numrows from tipomaterialcoleta where tipomaterialcoleta.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela tipomaterialcoleta.''; end if; select count(*) into numrows from salaatendimento where salaatendimento.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela salaatendimento.''; end if; select count(*) into numrows from agendamento where agendamento.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela agendamento.''; end if; select count(*) into numrows from requisicaoweb where requisicaoweb.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela requisicaoweb.''; end if; select count(*) into numrows from lanctoestoquecmc where lanctoestoquecmc.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela lanctoestoquecmc.''; end if; select count(*) into numrows from lanctoestoqueueps where lanctoestoqueueps.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela lanctoestoqueueps.''; end if; select count(*) into numrows from lanctoestoquepeps where lanctoestoquepeps.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela lanctoestoquepeps.''; end if; select count(*) into numrows from contrassenharequisicao where contrassenharequisicao.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela contrassenharequisicao.''; end if; select count(*) into numrows from solicitarsoroteca where solicitarsoroteca.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela solicitarsoroteca.''; end if; select count(*) into numrows from exportaintegracaohospital where exportaintegracaohospital.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela exportaintegracaohospital.''; end if; select count(*) into numrows from examerequisicaohistoricolaudo where examerequisicaohistoricolaudo.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicaohistoricolaudo.''; end if; select count(*) into numrows from examerequisicaosetor where examerequisicaosetor.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicaosetor.''; end if; select count(*) into numrows from materialenviado where materialenviado.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela materialenviado.''; end if; select count(*) into numrows from rota where rota.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela rota.''; end if; select count(*) into numrows from montagemkit where montagemkit.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela montagemkit.''; end if; select count(*) into numrows from transfestoque where transfestoque.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela transfestoque.''; end if; select count(*) into numrows from orcamento where orcamento.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela orcamento.''; end if; select count(*) into numrows from estoquemanual where estoquemanual.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela estoquemanual.''; end if; select count(*) into numrows from requisicaoestoque where requisicaoestoque.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela requisicaoestoque.''; end if; select count(*) into numrows from conferenciaestoque where conferenciaestoque.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela conferenciaestoque.''; end if; select count(*) into numrows from lanctoestoque where lanctoestoque.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela lanctoestoque.''; end if; select count(*) into numrows from conferenciaentrada where conferenciaentrada.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela conferenciaentrada.''; end if; select count(*) into numrows from pedido where pedido.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela pedido.''; end if; select count(*) into numrows from cotacao where cotacao.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela cotacao.''; end if; select count(*) into numrows from cfop where cfop.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela cfop.''; end if; select count(*) into numrows from celulaestoque where celulaestoque.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela celulaestoque.''; end if; select count(*) into numrows from unidadesaude where unidadesaude.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela unidadesaude.''; end if; select count(*) into numrows from estantes where estantes.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela estantes.''; end if; select count(*) into numrows from geladeiras where geladeiras.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela geladeiras.''; end if; delete from usuariofilial where usuariofilial.fil_codigo = old.fil_codigo; select count(*) into numrows from origemplanocusto where origemplanocusto.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela origemplanocusto.''; end if; select count(*) into numrows from filialimposto where filialimposto.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela filialimposto.''; end if; select count(*) into numrows from embalagemproduto where embalagemproduto.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela embalagemproduto.''; end if; select count(*) into numrows from notafiscal where notafiscal.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela notafiscal.''; end if; select count(*) into numrows from servico where servico.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela servico.''; end if; select count(*) into numrows from baixa where baixa.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela baixa.''; end if; select count(*) into numrows from receberpagar where receberpagar.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela receberpagar.''; end if; select count(*) into numrows from entidade where entidade.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela entidade.''; end if; select count(*) into numrows from motivoscancelamentos where motivoscancelamentos.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela motivoscancelamentos.''; end if; select count(*) into numrows from formapagto where formapagto.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela formapagto.''; end if; select count(*) into numrows from especie where especie.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela especie.''; end if; select count(*) into numrows from series where series.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela series.''; end if; delete from filiaisweb where filiaisweb.fil_kodigo = old.fil_codigo; delete from filiaisweb where filiaisweb.fil_codigo = old.fil_codigo; select count(*) into numrows from labexterno where labexterno.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela labexterno.''; end if; select count(*) into numrows from loteexterno where loteexterno.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela loteexterno.''; end if; select count(*) into numrows from log where log.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela log.''; end if; select count(*) into numrows from alahospital where alahospital.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela alahospital.''; end if; select count(*) into numrows from loteapoio where loteapoio.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela loteapoio.''; end if; select count(*) into numrows from exportaapoio where exportaapoio.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela exportaapoio.''; end if; select count(*) into numrows from exportafiliais where exportafiliais.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela exportafiliais.''; end if; select count(*) into numrows from requisicao where requisicao.fil_codcopia = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela requisicao.''; end if; select count(*) into numrows from filiaisexamesexportar where filiaisexamesexportar.fil_coddestino = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela filiaisexamesexportar.''; end if; select count(*) into numrows from contrasenha where contrasenha.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela contrasenha.''; end if; select count(*) into numrows from exportaweb where exportaweb.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela exportaweb.''; end if; select count(*) into numrows from interface where interface.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela interface.''; end if; select count(*) into numrows from banco where banco.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela banco.''; end if; select count(*) into numrows from agencia where agencia.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela agencia.''; end if; select count(*) into numrows from historicopadrao where historicopadrao.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela historicopadrao.''; end if; select count(*) into numrows from prioridade where prioridade.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela prioridade.''; end if; select count(*) into numrows from destino where destino.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela destino.''; end if; select count(*) into numrows from grupo where grupo.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela grupo.''; end if; select count(*) into numrows from feriados where feriados.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela feriados.''; end if; select count(*) into numrows from especialidades where especialidades.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela especialidades.''; end if; select count(*) into numrows from coletas where coletas.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela coletas.''; end if; select count(*) into numrows from tabelaprecoexames where tabelaprecoexames.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela tabelaprecoexames.''; end if; select count(*) into numrows from tipomaterial where tipomaterial.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela tipomaterial.''; end if; select count(*) into numrows from unidademedida where unidademedida.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela unidademedida.''; end if; select count(*) into numrows from situacao where situacao.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela situacao.''; end if; select count(*) into numrows from principios where principios.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela principios.''; end if; select count(*) into numrows from medicamentos where medicamentos.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela medicamentos.''; end if; select count(*) into numrows from layout where layout.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela layout.''; end if; select count(*) into numrows from metodologia where metodologia.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela metodologia.''; end if; select count(*) into numrows from recipientes where recipientes.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela recipientes.''; end if; select count(*) into numrows from cidades where cidades.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela cidades.''; end if; select count(*) into numrows from bairro where bairro.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela bairro.''; end if; select count(*) into numrows from materialcoleta where materialcoleta.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela materialcoleta.''; end if; select count(*) into numrows from prazoentrega where prazoentrega.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela prazoentrega.''; end if; select count(*) into numrows from historicos where historicos.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela historicos.''; end if; select count(*) into numrows from lanctocaixa where lanctocaixa.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela lanctocaixa.''; end if; select count(*) into numrows from centrocusto where centrocusto.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela centrocusto.''; end if; select count(*) into numrows from planoconta where planoconta.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela planoconta.''; end if; select count(*) into numrows from contacorrente where contacorrente.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela contacorrente.''; end if; select count(*) into numrows from material where material.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela material.''; end if; select count(*) into numrows from requisicao where requisicao.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela requisicao.''; end if; select count(*) into numrows from medico where medico.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela medico.''; end if; select count(*) into numrows from convenios where convenios.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela convenios.''; end if; delete from exames where exames.fil_codigo = old.fil_codigo; select count(*) into numrows from fatura where fatura.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela fatura.''; end if; select count(*) into numrows from setores where setores.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela setores.''; end if; select count(*) into numrows from paciente where paciente.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela paciente.''; end if; return old; end;' language 'plpgsql'; create trigger td_filiais_postocoleta after delete on filiais_postocoleta for each row execute procedure fn_td_filiais_postocoleta(); drop function fn_ti_filiais_postocoleta() cascade; create function fn_ti_filiais_postocoleta() returns opaque as ' declare numrows integer; tmp varchar; begin select count(*) into numrows from labexterno where new.fil_codigo = labexterno.fil_codigo and new.lae_codigo = labexterno.lae_codigo; tmp:=''labexterno|''; tmp:=tmp || ''fil_codigo='' || new.fil_codigo || ''|''; tmp:=tmp || ''lae_codigo='' || new.lae_codigo || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.fil_codigo is not null and new.lae_codigo is not null and numrows = 0 ) then raise exception ''o registro nao pode ser inserido, pois um valor informado nao existe na tabela labexterno. chave para consulta:[%]'',tmp using errcode=upper(''ifkne''); end if; select count(*) into numrows from usuario where new.usr_codcompras = usuario.usr_codigo; tmp:=''usuario|''; tmp:=tmp || ''usr_codigo='' || new.usr_codcompras || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.usr_codcompras is not null and numrows = 0 ) then raise exception ''o registro nao pode ser inserido, pois um valor informado nao existe na tabela usuario. chave para consulta:[%]'',tmp using errcode=upper(''ifkne''); end if; select count(*) into numrows from usuario where new.usr_codestoque = usuario.usr_codigo; tmp:=''usuario|''; tmp:=tmp || ''usr_codigo='' || new.usr_codestoque || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.usr_codestoque is not null and numrows = 0 ) then raise exception ''o registro nao pode ser inserido, pois um valor informado nao existe na tabela usuario. chave para consulta:[%]'',tmp using errcode=upper(''ifkne''); end if; select count(*) into numrows from bairro where new.fil_codigo = bairro.fil_codigo and new.bai_codigo = bairro.bai_codigo; tmp:=''bairro|''; tmp:=tmp || ''fil_codigo='' || new.fil_codigo || ''|''; tmp:=tmp || ''bai_codigo='' || new.bai_codigo || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.fil_codigo is not null and new.bai_codigo is not null and numrows = 0 ) then raise exception ''o registro nao pode ser inserido, pois um valor informado nao existe na tabela bairro. chave para consulta:[%]'',tmp using errcode=upper(''ifkne''); end if; select count(*) into numrows from cidades where new.fil_codigo = cidades.fil_codigo and new.cid_codigo = cidades.cid_codigo; tmp:=''cidades|''; tmp:=tmp || ''fil_codigo='' || new.fil_codigo || ''|''; tmp:=tmp || ''cid_codigo='' || new.cid_codigo || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.fil_codigo is not null and new.cid_codigo is not null and numrows = 0 ) then raise exception ''o registro nao pode ser inserido, pois um valor informado nao existe na tabela cidades. chave para consulta:[%]'',tmp using errcode=upper(''ifkne''); end if; return new; end;' language 'plpgsql'; create trigger ti_filiais_postocoleta after insert on filiais_postocoleta for each row execute procedure fn_ti_filiais_postocoleta(); drop function fn_tu_filiais_postocoleta() cascade; create function fn_tu_filiais_postocoleta() returns opaque as ' declare numrows integer; tmp varchar; begin if (old.fil_codigo <> new.fil_codigo) then select count(*) from motivorecoleta where motivorecoleta.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela motivorecoleta.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from logvalidalote where logvalidalote.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela logvalidalote.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from ambbpa where ambbpa.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela ambbpa.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from categoriaprodutoalimentos where categoriaprodutoalimentos.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela categoriaprodutoalimentos.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from responsavelcertificado where responsavelcertificado.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela responsavelcertificado.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from origemnaoconformidade where origemnaoconformidade.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela origemnaoconformidade.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from filialemailaniversario where filialemailaniversario.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela filialemailaniversario.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from filialsmsaniversario where filialsmsaniversario.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela filialsmsaniversario.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from logemail where logemail.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela logemail.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from filialsmsresumo where filialsmsresumo.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela filialsmsresumo.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from lanctocaixa where lanctocaixa.fil_codentrefilial = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela lanctocaixa.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from lotefilial where lotefilial.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela lotefilial.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from taxa where taxa.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela taxa.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from logoffline where logoffline.fil_coddestino = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela logoffline.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from logoffline where logoffline.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela logoffline.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from pais where pais.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela pais.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from logsms where logsms.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela logsms.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from naoconformidade where naoconformidade.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela naoconformidade.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from acaonaoconformidade where acaonaoconformidade.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela acaonaoconformidade.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from procedencianaoconformidade where procedencianaoconformidade.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela procedencianaoconformidade.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from banhomaria where banhomaria.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela banhomaria.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from identificadorlamina where identificadorlamina.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela identificadorlamina.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from materiallote where materiallote.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela materiallote.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from examerequisicaohash where examerequisicaohash.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicaohash.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from motivoalteracao where motivoalteracao.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela motivoalteracao.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from tipomaterialcoleta where tipomaterialcoleta.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela tipomaterialcoleta.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from salaatendimento where salaatendimento.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela salaatendimento.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from agendamento where agendamento.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela agendamento.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from requisicaoweb where requisicaoweb.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela requisicaoweb.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from lanctoestoquecmc where lanctoestoquecmc.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela lanctoestoquecmc.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from lanctoestoqueueps where lanctoestoqueueps.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela lanctoestoqueueps.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from lanctoestoquepeps where lanctoestoquepeps.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela lanctoestoquepeps.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from contrassenharequisicao where contrassenharequisicao.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela contrassenharequisicao.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from solicitarsoroteca where solicitarsoroteca.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela solicitarsoroteca.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from exportaintegracaohospital where exportaintegracaohospital.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela exportaintegracaohospital.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from examerequisicaohistoricolaudo where examerequisicaohistoricolaudo.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicaohistoricolaudo.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from examerequisicaosetor where examerequisicaosetor.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicaosetor.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from materialenviado where materialenviado.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela materialenviado.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from rota where rota.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela rota.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from montagemkit where montagemkit.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela montagemkit.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from transfestoque where transfestoque.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela transfestoque.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from orcamento where orcamento.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela orcamento.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from estoquemanual where estoquemanual.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela estoquemanual.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from requisicaoestoque where requisicaoestoque.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela requisicaoestoque.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from conferenciaestoque where conferenciaestoque.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela conferenciaestoque.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from lanctoestoque where lanctoestoque.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela lanctoestoque.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from conferenciaentrada where conferenciaentrada.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela conferenciaentrada.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from pedido where pedido.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela pedido.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from cotacao where cotacao.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela cotacao.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from cfop where cfop.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela cfop.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from celulaestoque where celulaestoque.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela celulaestoque.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from unidadesaude where unidadesaude.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela unidadesaude.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from estantes where estantes.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela estantes.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from geladeiras where geladeiras.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela geladeiras.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from origemplanocusto where origemplanocusto.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela origemplanocusto.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from filialimposto where filialimposto.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela filialimposto.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from embalagemproduto where embalagemproduto.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela embalagemproduto.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from notafiscal where notafiscal.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela notafiscal.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from servico where servico.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela servico.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from baixa where baixa.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela baixa.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from receberpagar where receberpagar.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela receberpagar.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from entidade where entidade.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela entidade.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from motivoscancelamentos where motivoscancelamentos.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela motivoscancelamentos.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from formapagto where formapagto.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela formapagto.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from especie where especie.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela especie.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from series where series.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela series.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from filiaisweb where filiaisweb.fil_kodigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela filiaisweb.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from filiaisweb where filiaisweb.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela filiaisweb.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from labexterno where labexterno.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela labexterno.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from loteexterno where loteexterno.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela loteexterno.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from log where log.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela log.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from alahospital where alahospital.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela alahospital.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from loteapoio where loteapoio.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela loteapoio.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from exportaapoio where exportaapoio.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela exportaapoio.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from exportafiliais where exportafiliais.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela exportafiliais.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from requisicao where requisicao.fil_codcopia = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela requisicao.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from filiaisexamesexportar where filiaisexamesexportar.fil_coddestino = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela filiaisexamesexportar.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from contrasenha where contrasenha.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela contrasenha.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from exportaweb where exportaweb.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela exportaweb.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from interface where interface.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela interface.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from banco where banco.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela banco.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from agencia where agencia.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela agencia.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from historicopadrao where historicopadrao.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela historicopadrao.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from prioridade where prioridade.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela prioridade.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from destino where destino.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela destino.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from grupo where grupo.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela grupo.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from feriados where feriados.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela feriados.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from especialidades where especialidades.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela especialidades.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from coletas where coletas.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela coletas.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from tabelaprecoexames where tabelaprecoexames.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela tabelaprecoexames.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from tipomaterial where tipomaterial.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela tipomaterial.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from unidademedida where unidademedida.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela unidademedida.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from situacao where situacao.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela situacao.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from principios where principios.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela principios.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from medicamentos where medicamentos.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela medicamentos.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from layout where layout.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela layout.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from metodologia where metodologia.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela metodologia.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from recipientes where recipientes.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela recipientes.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from cidades where cidades.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela cidades.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from bairro where bairro.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela bairro.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from materialcoleta where materialcoleta.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela materialcoleta.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from prazoentrega where prazoentrega.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela prazoentrega.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from historicos where historicos.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela historicos.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from lanctocaixa where lanctocaixa.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela lanctocaixa.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from centrocusto where centrocusto.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela centrocusto.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from planoconta where planoconta.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela planoconta.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from contacorrente where contacorrente.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela contacorrente.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from material where material.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela material.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from requisicao where requisicao.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela requisicao.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from medico where medico.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela medico.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from convenios where convenios.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela convenios.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from exames where exames.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela exames.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from fatura where fatura.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela fatura.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from setores where setores.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela setores.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from paciente where paciente.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela paciente.''; end if; end if; select count(*) into numrows from labexterno where new.fil_codigo = labexterno.fil_codigo and new.lae_codigo = labexterno.lae_codigo; tmp:=''labexterno|''; tmp:=tmp || ''fil_codigo='' || new.fil_codigo || ''|''; tmp:=tmp || ''lae_codigo='' || new.lae_codigo || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.fil_codigo is not null and new.lae_codigo is not null and numrows = 0 ) then raise exception ''o registro nao pode ser alterado, pois um valor nao existe na tabela labexterno. chave para consulta:[%]'',tmp using errcode=upper(''ufkne''); end if; select count(*) into numrows from usuario where new.usr_codcompras = usuario.usr_codigo; tmp:=''usuario|''; tmp:=tmp || ''usr_codigo='' || new.usr_codcompras || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.usr_codcompras is not null and numrows = 0 ) then raise exception ''o registro nao pode ser alterado, pois um valor nao existe na tabela usuario. chave para consulta:[%]'',tmp using errcode=upper(''ufkne''); end if; select count(*) into numrows from usuario where new.usr_codestoque = usuario.usr_codigo; tmp:=''usuario|''; tmp:=tmp || ''usr_codigo='' || new.usr_codestoque || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.usr_codestoque is not null and numrows = 0 ) then raise exception ''o registro nao pode ser alterado, pois um valor nao existe na tabela usuario. chave para consulta:[%]'',tmp using errcode=upper(''ufkne''); end if; select count(*) into numrows from bairro where new.fil_codigo = bairro.fil_codigo and new.bai_codigo = bairro.bai_codigo; tmp:=''bairro|''; tmp:=tmp || ''fil_codigo='' || new.fil_codigo || ''|''; tmp:=tmp || ''bai_codigo='' || new.bai_codigo || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.fil_codigo is not null and new.bai_codigo is not null and numrows = 0 ) then raise exception ''o registro nao pode ser alterado, pois um valor nao existe na tabela bairro. chave para consulta:[%]'',tmp using errcode=upper(''ufkne''); end if; select count(*) into numrows from cidades where new.fil_codigo = cidades.fil_codigo and new.cid_codigo = cidades.cid_codigo; tmp:=''cidades|''; tmp:=tmp || ''fil_codigo='' || new.fil_codigo || ''|''; tmp:=tmp || ''cid_codigo='' || new.cid_codigo || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.fil_codigo is not null and new.cid_codigo is not null and numrows = 0 ) then raise exception ''o registro nao pode ser alterado, pois um valor nao existe na tabela cidades. chave para consulta:[%]'',tmp using errcode=upper(''ufkne''); end if; return old; end;' language 'plpgsql'; create trigger tu_filiais_postocoleta after update on filiais_postocoleta for each row execute procedure fn_tu_filiais_postocoleta(); create function fn_td_motivorecoleta() returns opaque as ' declare numrows integer; begin select count(*) into numrows from examerequisicao where examerequisicao.fil_codigo = old.fil_codigo and examerequisicao.mrc_codigo = old.mrc_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicao.''; end if; return old; end;' language 'plpgsql'; create trigger td_motivorecoleta after delete on motivorecoleta for each row execute procedure fn_td_motivorecoleta(); create function fn_ti_motivorecoleta() returns opaque as ' declare numrows integer; tmp varchar; begin select count(*) into numrows from filiais_postocoleta where new.fil_codigo = filiais_postocoleta.fil_codigo; tmp:=''filiais_postocoleta|''; tmp:=tmp || ''fil_codigo='' || new.fil_codigo || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( numrows = 0 ) then raise exception ''o registro nao pode ser inserido, pois um valor informado nao existe na tabela filiais_postocoleta. chave para consulta:[%]'',tmp using errcode=upper(''ifkne''); end if; return new; end;' language 'plpgsql'; create trigger ti_motivorecoleta after insert on motivorecoleta for each row execute procedure fn_ti_motivorecoleta(); create function fn_tu_motivorecoleta() returns opaque as ' declare numrows integer; tmp varchar; begin if (old.fil_codigo <> new.fil_codigo or old.mrc_codigo <> new.mrc_codigo) then select count(*) from examerequisicao where examerequisicao.fil_codigo = old.fil_codigo and examerequisicao.mrc_codigo = old.mrc_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicao.''; end if; end if; select count(*) into numrows from filiais_postocoleta where new.fil_codigo = filiais_postocoleta.fil_codigo; tmp:=''filiais_postocoleta|''; tmp:=tmp || ''fil_codigo='' || new.fil_codigo || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( numrows = 0 ) then raise exception ''o registro nao pode ser alterado, pois um valor nao existe na tabela filiais_postocoleta. chave para consulta:[%]'',tmp using errcode=upper(''ufkne''); end if; return old; end;' language 'plpgsql'; create trigger tu_motivorecoleta after update on motivorecoleta for each row execute procedure fn_tu_motivorecoleta(); insert into atualizacoes(atu_nome) values ('v18020003_160218.sql'); alter table labexterno add lae_inativo boolean; alter table interface add int_inativo boolean; alter table parametros add par_copiacategoriaprodutoalimentos varchar(200), add par_copiaprodutoalimentos varchar(200); insert into atualizacoes(atu_nome) values ('v18020004_190218.sql');