[firebase-br] SP retonando Dado Inserido

viniciusf em grupojvp.com.br viniciusf em grupojvp.com.br
Qua Set 12 15:57:03 -03 2012


Estou com um problema... Criei uma Stored Procedure que Gera Uma nova 
ordem de serviço... porém não sei como fazer no firebird em uma SP de 
inserção... me retornar o COD da ordem de serviço que foi inserida...

Tentei colocar no final da SP um select MAX(ID) e me retornando um 
inteiro.. funcionou... porem sempre que executo ela pelo dbx delphi pelo 
modo SELECT * FROM SP_GERAR(1,2) ela puxa execption que nao deveria 
puxar... se uso com EXECUTE PROCEDURE... funciona normal... Porem não me 
retorna o valor...


begin
   PLACA = trim(upper(PLACA));

   select count(*)
   from VIATURA
   where (VIATURA.PLACA = :PLACA)
   into :QTDVIAT;

   if (QTDVIAT = 0) then
   begin
     exception VIATURA_INEXISTENTE;
   end

   select count(*)
   from OS
   where (OS.PLACA_VIATURA = :PLACA) and
         ((OS.STATUS = 'ABERTA') or (OS.STATUS = 'PARADA'))
   into :QTDOS;

   if (QTDOS > 0) then
   begin
     exception OS_ABERTA;
   end

   if (exists(select *
              from OS
              where OS.PLACA_VIATURA = :PLACA and
                    OS.STATUS <> 'EXCLUIDA')) then
   begin
     select max(OS.KM)
     from OS
     where (OS.PLACA_VIATURA = :PLACA)
     into :VAR_KM;
   end
   else
   begin
     VAR_KM = 0;
   end

   if (VAR_KM >= KM) then
   begin
     exception KM_INCORRETO;
   end

   insert into OS (OS.PLACA_VIATURA, OS.KM)
   values (:PLACA, :KM);

   select max(OS.COD)
   from OS
   into :COD;

   suspend;

end




Mais detalhes sobre a lista de discussão lista