验证输入的物料单位是否正确

1. 首先找到物料的主单位及是否可以进行单位换算。

 

SELECT PRIMARY_UOM_CODE,
         ALLOWED_UNITS_LOOKUP_CODE
  FROM mtl_system_items     msi,
         MTL_UNITS_OF_MEASURE MTLUOM2
 WHERE msi.ORGANIZATION_ID = &107
    AND msi.INVENTORY_ITEM_ID = &1399007
    AND MTLUOM2.uom_code = msi.PRIMARY_UOM_CODE
    AND NVL(MTLUOM2.DISABLE_DATE, TRUNC(SYSDATE) + 1) > TRUNC(SYSDATE);
 

 

2. 在标准换算率中查找是否有对应的单位。

 

--如MM -> CM -> M
SELECT MTLUOM2.uom_code,
         MTLUCV.uom_class
  FROM MTL_UNITS_OF_MEASURE MTLUOM2,
         MTL_UOM_CONVERSIONS  MTLUCV,
         MTL_UOM_CLASSES      MTLCLS
 WHERE MTLUOM2.uom_code = &L_UOM_CODE --'CM'
    AND MTLUCV.uom_code = MTLUOM2.uom_code
    AND MTLUCV.inventory_item_id = 0
    AND MTLCLS.uom_class = MTLUOM2.uom_class
    AND NVL(MTLCLS.DISABLE_DATE, TRUNC(SYSDATE) + 1) > TRUNC(SYSDATE)
    AND NVL(MTLUCV.DISABLE_DATE, TRUNC(SYSDATE) + 1) > TRUNC(SYSDATE)
    AND NVL(MTLUOM2.DISABLE_DATE, TRUNC(SYSDATE) + 1) > TRUNC(SYSDATE)
    AND MTLUCV.uom_class =
         (SELECT MTLPRI1.uom_class
             FROM MTL_UNITS_OF_MEASURE MTLPRI1
            WHERE MTLPRI1.uom_code = &primary_uom_code --'M'
              AND NVL(MTLPRI1.DISABLE_DATE, TRUNC(SYSDATE) + 1) > TRUNC(SYSDATE));

 

 

 

 3. 在同类别单位列表中查找是否有对应单位
SELECT MTLUOM2.uom_code,
         MTLUCV.uom_class
  FROM MTL_UNITS_OF_MEASURE MTLUOM2,
         MTL_UOM_CONVERSIONS  MTLUCV,
         MTL_UOM_CLASSES      MTLCLS
 WHERE /*MTLUOM2.uom_code = &p_uom_code
    AND*/ MTLUCV.uom_code = MTLUOM2.uom_code
    AND MTLUCV.inventory_item_id = &p_item_id
    AND MTLCLS.uom_class = MTLUOM2.uom_class
    AND NVL(MTLCLS.DISABLE_DATE, TRUNC(SYSDATE) + 1) > TRUNC(SYSDATE)
    AND NVL(MTLUOM2.DISABLE_DATE, TRUNC(SYSDATE) + 1) > TRUNC(SYSDATE)
    AND NVL(MTLUCV.DISABLE_DATE, TRUNC(SYSDATE) + 1) > TRUNC(SYSDATE);
 

 

4. 复杂的查找。除了以上情况外,在不同类别的转换关系中查找是否有对应的单位

SELECT MTLUOM2.uom_code,
         MTLUOM2.uom_class
  FROM MTL_UNITS_OF_MEASURE MTLUOM2,
         MTL_UOM_CONVERSIONS  MTLUCV,
         MTL_UOM_CLASSES      MTLCLS
 WHERE MTLUOM2.uom_code = p_uom_code
    AND MTLUCV.uom_code = MTLUOM2.uom_code
    AND MTLCLS.uom_class = MTLUOM2.uom_class
    AND NVL(MTLCLS.DISABLE_DATE, TRUNC(SYSDATE) + 1) > TRUNC(SYSDATE)
    AND NVL(MTLUOM2.DISABLE_DATE, TRUNC(SYSDATE) + 1) > TRUNC(SYSDATE)
    AND NVL(MTLUCV.DISABLE_DATE, TRUNC(SYSDATE) + 1) > TRUNC(SYSDATE)
    AND l_allowed_units IN (1, 3)
    AND MTLUCV.inventory_item_id = p_item_id
UNION ALL
SELECT MTLUOM2.uom_code,
         MTLUOM2.uom_class
  FROM MTL_UNITS_OF_MEASURE MTLUOM2,
         MTL_UOM_CONVERSIONS  MTLUCV,
         MTL_UOM_CLASSES      MTLCLS
 WHERE MTLUOM2.uom_code = p_uom_code
    AND MTLUCV.uom_code = MTLUOM2.uom_code
    AND MTLCLS.uom_class = MTLUOM2.uom_class
    AND NVL(MTLCLS.DISABLE_DATE, TRUNC(SYSDATE) + 1) > TRUNC(SYSDATE)
    AND NVL(MTLUOM2.DISABLE_DATE, TRUNC(SYSDATE) + 1) > TRUNC(SYSDATE)
    AND NVL(MTLUCV.DISABLE_DATE, TRUNC(SYSDATE) + 1) > TRUNC(SYSDATE)
    AND l_allowed_units IN (1, 3)
    AND MTLUCV.inventory_item_id = 0
    AND MTLUCV.uom_class =
         (SELECT MTLPRI1.uom_class
             FROM MTL_UNITS_OF_MEASURE MTLPRI1
            WHERE MTLPRI1.uom_code = l_primary_uom_code)
UNION ALL
SELECT MTLUOM2.uom_code,
         MTLUOM2.uom_class
  FROM MTL_UNITS_OF_MEASURE MTLUOM2,
         MTL_UOM_CONVERSIONS  MTLUCV,
         MTL_UOM_CLASSES      MTLCLS
 WHERE MTLUOM2.uom_code = p_uom_code
    AND MTLUCV.uom_code = MTLUOM2.uom_code
    AND MTLCLS.uom_class = MTLUOM2.uom_class
    AND NVL(MTLCLS.DISABLE_DATE, TRUNC(SYSDATE) + 1) > TRUNC(SYSDATE)
    AND NVL(MTLUOM2.DISABLE_DATE, TRUNC(SYSDATE) + 1) > TRUNC(SYSDATE)
    AND NVL(MTLUCV.DISABLE_DATE, TRUNC(SYSDATE) + 1) > TRUNC(SYSDATE)
    AND l_allowed_units IN (1, 3)
    AND MTLUCV.inventory_item_id = 0
    AND EXISTS
 (SELECT 'UOM_CLASS conversion exists for the class of UOM supplied'
             FROM MTL_UOM_CLASS_CONVERSIONS MTLUCC1
            WHERE MTLUCC1.to_uom_class = MTLUCV.uom_class
              AND MTLUCC1.inventory_item_id = p_item_id
              AND NVL(MTLUCC1.DISABLE_DATE, TRUNC(SYSDATE) + 1) > TRUNC(SYSDATE))
UNION ALL
SELECT MTLUOM2.uom_code,
         MTLUOM2.uom_class
  FROM MTL_UNITS_OF_MEASURE MTLUOM2,
         MTL_UOM_CONVERSIONS  MTLUCV,
         MTL_UOM_CLASSES      MTLCLS
 WHERE MTLUOM2.uom_code = p_uom_code
    AND MTLUCV.uom_code = MTLUOM2.uom_code
    AND MTLCLS.uom_class = MTLUOM2.uom_class
    AND NVL(MTLCLS.DISABLE_DATE, TRUNC(SYSDATE) + 1) > TRUNC(SYSDATE)
    AND NVL(MTLUOM2.DISABLE_DATE, TRUNC(SYSDATE) + 1) > TRUNC(SYSDATE)
    AND NVL(MTLUCV.DISABLE_DATE, TRUNC(SYSDATE) + 1) > TRUNC(SYSDATE)
    AND l_allowed_units IN (2, 3)
    AND MTLUCV.inventory_item_id = 0
    AND EXISTS
 (SELECT 'UOM_CLASS conversion exists for the class of UOM supplied'
             FROM MTL_UOM_CLASS_CONVERSIONS MTLUCC
            WHERE MTLUCC.to_uom_class = MTLUCV.uom_class
              AND MTLUCC.INVENTORY_ITEM_ID = p_item_id
              AND NVL(MTLUCC.DISABLE_DATE, TRUNC(SYSDATE) + 1) > TRUNC(SYSDATE))
UNION ALL
SELECT MTLUOM2.uom_code,
         MTLUOM2.uom_class
  FROM MTL_UNITS_OF_MEASURE MTLUOM2,
         MTL_UOM_CONVERSIONS  MTLUCV,
         MTL_UOM_CLASSES      MTLCLS
 WHERE MTLUOM2.uom_code = p_uom_code
    AND MTLUCV.uom_code = MTLUOM2.uom_code
    AND MTLCLS.uom_class = MTLUOM2.uom_class
    AND NVL(MTLCLS.DISABLE_DATE, TRUNC(SYSDATE) + 1) > TRUNC(SYSDATE)
    AND NVL(MTLUOM2.DISABLE_DATE, TRUNC(SYSDATE) + 1) > TRUNC(SYSDATE)
    AND NVL(MTLUCV.DISABLE_DATE, TRUNC(SYSDATE) + 1) > TRUNC(SYSDATE)
    AND l_allowed_units IN (2, 3)
    AND MTLUCV.inventory_item_id = 0
    AND MTLUCV.uom_class =
         (SELECT MTLPRI.uom_class
             FROM MTL_UNITS_OF_MEASURE MTLPRI
            WHERE MTLPRI.uom_code = l_primary_uom_code);

 

oracle判断单位是否填入正确的标准函数:

inv_convert.validate_item_uom(p_uom_code IN VARCHAR2,
                p_item_id  IN NUMBER,
                p_organization_id IN NUMBER);

 

posted @ 2011-09-13 15:08  郭振斌  阅读(833)  评论(0编辑  收藏  举报