CREATE OR ALTER PROCEDURE SPU_LOTE_PECA_ITEM (
    LOTE_PECA INTEGER)
AS
DECLARE VARIABLE ID         INTEGER;
DECLARE VARIABLE PECA_ID    INTEGER;
DECLARE VARIABLE SALDO      NUMERIC(15,4);
DECLARE VARIABLE ITEM_SALDO NUMERIC(15,4);
begin
   for select a.ID, a.peca_id, b.saldo, a.peca_saldo from tblote_peca_item a, tbrevisao b where a.LOTE_PECA_ID = :LOTE_PECA AND A.PECA_ID = B.ID into id, peca_id, saldo, item_saldo do
   begin
    if(:item_saldo is null) then
        begin
            UPDATE TBLOTE_PECA_ITEM c set c.PECA_SALDO = :saldo where c.ID = :id;
        end
   end
end;