PAGUE 6 MESES
LEVE 12 MESES
GARANTIR DESCONTO

Fórum Erro com SQL(Ajuda) #478653

12/05/2014

0

Bom dia estou tendo um erro com SQL onde me retorna o seguinte erro 'Multiple rows in singleton select' at trigger 'nome_trigger_BIUDO'

A Trigger é essa

declare variable vserie         varchar(25);
declare variable vCodEmpresa    integer;
declare variable vcrz           integer;
declare variable vcod_pdv       integer  ;
begin
  /* Trigger text */

  if (inserting) then
  begin
     voperacao = 'I';
     vCod_Marca     = new.cod_marca;
     vserie         = new.serie;
     vcrz           = new.crz;
  end
  else if (updating) then
  begin
     voperacao = 'U' ;
     vCod_Marca     = new.cod_marca;
     vserie         = new.serie;
     vcrz           = new.crz;
  end
  else
  begin
     voperacao = 'D' ;
     vCod_Marca     = old.cod_marca;
     vserie         = old.serie;
     vcrz           = old.crz;
  end

  select distinct pv.cod_pv, pv.cod_empresa
   from pv_movimento  pv left outer join vendas v
          on (pv.cod_empresa  = v.pv_cod_empresa and pv.cod_mov = v.pv_cod_mov )
  where v.cod_marca  = :vcod_marca
    and v.serie      = :vserie
    into vcod_pdv, vCodEmpresa ;

  execute procedure pr_integracao('FISCAL_MAPA_RESUMO', --tabela
                                        :vOperacao,  --operacao
                                        'A',         -- situacao
                                        :vCod_marca, --chave 1
                                        :vcrz,      --chave 2
                                        :vCodEmpresa,        --chave 3
                                        null,         --chave 4
                                        :vCod_pdv,    -- pdv
                                        null,         --idimportar
                                        null,         --usuario cancelamento
                                        null ,         --erro
                                        :vSerie,
                                        null) ;



end


A procedure que chama é essa:

begin


  select id_tabela_base
    from teste_tabela_base
   where nome_tabela_pdv = :ptabela into vid_tabela_base;

  if (vid_tabela_base is null ) then
  begin
    exception erro_teste_tabela_base;
  end

  if (:pid_importar IS NULL) then  -- inseri uma integracao
  begin

    select count(*) qtde
      from teste_importar i
     where i.id_tabela_base     = :vid_tabela_base
       and sequencial_pdv       = :psequencial_pdv
       and coalesce(chave1, 0)  = coalesce(:pchave1, 0)
       and coalesce(chave2, 0)  = coalesce(:pchave2, 0)
       and coalesce(chave3, 0)  = coalesce(:pchave3, 0)
       and coalesce(chave4, 0)  = coalesce(:pchave4, 0)
       and coalesce(chave5,'x') = coalesce(:pchave5,'x')
       and coalesce(chave6,'x') = coalesce(:pchave6,'x')
       and operacao            = :poperacao
       and situacao_integracao = 'A'
      into vexisteregistros;

    if (coalesce(vexisteregistros, 0) <= 0) then
    begin
        insert into teste_importar ( id_importar ,
                                   id_tabela_base ,
                                    Data_Inclusao,
                                    sequencial_pdv ,
                                    chave1,
                                    chave2,
                                    chave3,
                                    chave4,
                                    operacao,
                                    data_atualizacao,
                                    erro_atualizacao ,
                                    data_cancelamento,
                                    usuario_cancelamento,
                                    situacao_integracao,
                                    chave5,
                                    chave6)
                            values  (GEN_ID( steste_importar, 1 ),
                                    :vId_tabela_base ,
                                    current_timestamp,
                                    :pSequencial_pdv ,
                                    :pChave1,
                                    :pChave2,
                                    :pChave3,
                                    :pChave4,
                                    :pOperacao,
                                    null,
                                    null,
                                    null,
                                    null,
                                    'A',
                                    :pChave5,
                                    :pChave6);
    end
  end
  else if (:psituacao = 'C') then --cancela a integracao
  begin
    update teste_importar set data_cancelamento    = current_date  ,
                              usuario_cancelamento = :pusuario_cancelamento ,
                              situacao_integracao  = :psituacao
    where id_importar = :pid_importar;
  end
  else if (:psituacao = 'I') then --integrado
  begin
    update teste_importar set data_atualizacao = current_date  ,
                              situacao_integracao  = :psituacao
    where id_importar = :pid_importar;
  end
  else if (:psituacao = 'E') then --Erro de integracao
  begin
    update teste_importar set erro_atualizacao     = :pErro  ,
                              situacao_integracao  = :psituacao
    where id_importar = :pid_importar;
  end

  suspend;
end


Grato desde já
Gustavo Signorello

Gustavo Signorello

Responder

Posts

03/06/2014

Gustavo Signorello

Resolvido
Responder

Gostei + 0

Utilizamos cookies para fornecer uma melhor experiência para nossos usuários, consulte nossa política de privacidade.

Aceitar