I've done the following query, which was ordered by the product batch creation date. With the migration from version 11 to Oracle R12, the batch field became the migration date, that is, yesterday. As a workaround, we'll use the lote
field, which contains the original creation date. But order by sorts as numeric, not as date. How could in SQL change to this field be sorted as being out of date?
SQL:
Select
-- i.item_no Codigo,
msi.segment1 Codigo,
-- i.item_desc1 Descricao,
msi.description Descricao,
-- l.lot_no,
mln.lot_number Lote,
--l.sublot_no,
mln.parent_lot_number Sublote,
-- l.lot_desc,
mln.description Desc_Lote,
-- l.qc_grade,
mln.grade_code,
-- l.expaction_code,
mln.expiration_action_code,
-- l.inactive_ind,
nvl(mln.disable_flag,'1') Ativo,
-- l.origination_type,
mln.origination_type,
-- l.expaction_date,
mln.expiration_action_code,
-- l.lot_created,
mln.creation_date Data_Criacao,
-- l.expire_date,
mln.expiration_date,
-- l.retest_date,
mln.retest_date,
-- round(sysdate - l.lot_created) Dias,
round(sysdate - mln.creation_date) Dias,
-- round(sum(ili.loct_onhand)) qtde
round(sum(moq.transaction_quantity)) qtde
From mtl_lot_numbers mln,
mtl_system_items msi,
mtl_onhand_quantities moq,
mtl_item_locations mil
WHERE msi.inventory_item_id = mln.inventory_item_id
and msi.organization_id = mln.organization_id
and msi.inventory_item_id = moq.inventory_item_id
and msi.organization_id = moq.organization_id
-- and msi.organization_id = 131 -- SOMENTE PA0
and moq.locator_id = mil.inventory_location_id
and msi.segment1 between '80000' and '99999'
-- and l.lot_id != 0 -- NAO EXISTE MAIS
--and i.item_no >= nvl(CodigoIni,'80000')
--and i.item_no <= nvl(CodigoFim,'99999')
group by msi.segment1,
msi.description,
mln.lot_number,
mln.parent_lot_number,
mln.description,
mln.grade_code,
mln.expiration_action_code,
nvl(mln.disable_flag,'1'),
mln.origination_type,
mln.expiration_action_code,
mln.creation_date,
mln.expiration_date,
mln.retest_date,
round(sysdate - mln.creation_date)
having round(sum(moq.transaction_quantity)) > 0
Order by 2 asc,15 asc
Current result: