|
|

楼主 |
发表于 2012/12/12 15:48:58
|
显示全部楼层
下面是他写的sql语句
SELECT t.ou_name ou_name,t.created_by created_by,
m.subinv_from subinv_from,
n.subinv_to subinv_to,
--fnd_profile.VALUE('USERNAME') user_name,
case when (:p_source_from is not null or :p_source_to is not null) then to_number(t.source_name)
when (:p_order_from is not null or :p_order_to is not null) then t.order_num else t.transaction_set_id end group_by,
to_char(t.transaction_date, 'yyyy-mm-dd') transaction_date,
t.item_code item_code,
t.item_name item_name,
abs(t.primary_quantity) primary_quantity,
t.primary_uom_code primary_uom_code,
abs(t.secondary_quantity) secondary_quantity,
t.secondary_uom_code secondary_uom_code,
t.lot_number lot_number
FROM (SELECT hou.NAME ou_name,mmt.created_by created_by,mmt.transaction_set_id transaction_set_id,
mmt.transaction_id,
mmt.transaction_id order_num,
mmt.transaction_date transaction_date,
msi.segment1 item_code,
msi.description item_name,
mmt.primary_quantity primary_quantity,
(SELECT t.unit_of_measure FROM mtl_units_of_measure_vl t WHERE t.uom_code = msi.primary_uom_code) primary_uom_code,
mmt.secondary_transaction_quantity secondary_quantity,
(SELECT t.unit_of_measure FROM mtl_units_of_measure_vl t WHERE t.uom_code =msi.secondary_uom_code) secondary_uom_code,
mtlv.lot_number lot_number,
mmt.transaction_source_name source_name
FROM mtl_material_transactions mmt,
mtl_system_items_b msi,
mtl_transaction_lot_val_v mtlv,
--mtl_item_locations mil,
org_organization_definitions ood,
hr_organization_units hou
WHERE mmt.inventory_item_id = msi.inventory_item_id
AND mmt.organization_id = msi.organization_id
AND mmt.transaction_id = mtlv.transaction_id(+)
AND mmt.transaction_type_id = 2
--AND mmt.locator_id = mil.inventory_location_id(+)
AND mmt.organization_id = ood.organization_id
AND ood.operating_unit = hou.organization_id
AND mtlv.lot_number IS NULL
AND mmt.primary_quantity < 0
AND hou.organization_id = fnd_profile.VALUE('ORG_ID')
UNION ALL
SELECT hou.NAME ou_name,mmt.created_by created_by,mmt.transaction_set_id transaction_set_id,
mmt.transaction_id,
mmt.transaction_id order_num,
mmt.transaction_date transaction_date,
msi.segment1 item_code,
msi.description item_name,
mtlv.primary_quantity primary_quantity,
(SELECT t.unit_of_measure FROM mtl_units_of_measure_vl t WHERE t.uom_code = msi.primary_uom_code) primary_uom_code,
mtlv.secondary_transaction_quantity secondary_quantity,
(SELECT t.unit_of_measure FROM mtl_units_of_measure_vl t WHERE t.uom_code =msi.secondary_uom_code) secondary_uom_code,
mtlv.lot_number lot_number,
mmt.transaction_source_name source_name
FROM mtl_material_transactions mmt,
mtl_system_items_b msi,
mtl_transaction_lot_val_v mtlv,
--mtl_item_locations mil,
org_organization_definitions ood,
hr_organization_units hou
WHERE mmt.inventory_item_id = msi.inventory_item_id
AND mmt.organization_id = msi.organization_id
AND mmt.transaction_id = mtlv.transaction_id(+)
AND mmt.transaction_type_id = 2
--AND mmt.locator_id = mil.inventory_location_id(+)
AND mmt.organization_id = ood.organization_id
AND ood.operating_unit = hou.organization_id
AND mtlv.lot_number IS NOT NULL
AND mmt.primary_quantity < 0
AND hou.organization_id = fnd_profile.VALUE('ORG_ID')
) t,
(SELECT mmt.transaction_id,
decode(mil.description,
NULL,
msif.description,
msif.description || '一' || mil.description) subinv_from
FROM mtl_material_transactions mmt,
mtl_item_locations mil,
mtl_secondary_inventories_fk_v msif
WHERE mmt.locator_id = mil.inventory_location_id(+)
AND mmt.subinventory_code = msif.secondary_inventory_name(+)
AND mmt.organization_id = msif.organization_id
AND mmt.transaction_type_id = 2) m,
(SELECT mmt.transaction_id,
decode(mil.description,
NULL,
msif.description,
msif.description || '一' || mil.description) subinv_to
FROM mtl_material_transactions mmt,
mtl_item_locations mil,
mtl_secondary_inventories_fk_v msif
WHERE mmt.transaction_type_id = 2
AND mmt.transfer_locator_id = mil.inventory_location_id(+)
AND mmt.transfer_subinventory = msif.secondary_inventory_name(+)
AND mmt.organization_id = msif.organization_id) n
WHERE m.transaction_id = t.transaction_id
AND n.transaction_id = t.transaction_id
--and lpad(t.source_name,length(:p_source_to),'0') >= lpad(:p_source_from,length(:p_source_to),'0')
--and lpad(t.source_name,length(:p_source_to),'0') <= :p_source_to
&p_where
ORDER BY case when (:p_source_from is not null or :p_source_to is not null) then to_number(t.source_name)
when (:p_order_from is not null or :p_order_to is not null) then t.order_num else t.transaction_set_id end,item_code; |
|