实际上,Oracle把各成本子要素的定义都存储在bom_resources表中,所以写SQL的时候需要注意自连接的使用,不要混淆。
制造费用关联的资源:
SELECT owh.organization_id,
owh.resource_code overhead_code,
owh.description,
lov_cse.meaning cost_element,
lov_dbs.meaning default_basis_type,
res.resource_code resource_code
FROM bom.bom_resources owh,
apps.fnd_lookup_values_vl lov_cse,
apps.fnd_lookup_values_vl lov_dbs,
bom.cst_resource_overheads cro,
bom.bom_resources res
WHERE owh.cost_element_id = lov_cse.lookup_code
AND 'CST_COST_CODE_TYPE' = lov_cse.lookup_type
AND owh.default_basis_type = lov_dbs.lookup_code
AND 'CST_BASIS' = lov_dbs.lookup_type
AND owh.resource_id = cro.overhead_id
AND cro.resource_id = res.resource_id
AND owh.organization_id = 104
AND owh.cost_element_id = 5 -- Element
AND cro.cost_type_id = 1 --Cost Type
ORDER BY 1, 2;
制造费用的部门费率:
SELECT owh.organization_id,
owh.resource_code overhead_code,
owh.description,
lov_cse.meaning cost_element,
lov_dbs.meaning default_basis_type,
dept.department_code,
cdo.rate_or_amount
FROM bom.bom_resources owh,
apps.fnd_lookup_values_vl lov_cse,
apps.fnd_lookup_values_vl lov_dbs,
bom.cst_department_overheads cdo,
bom.bom_departments dept
WHERE owh.cost_element_id = lov_cse.lookup_code
AND 'CST_COST_CODE_TYPE' = lov_cse.lookup_type
AND owh.default_basis_type = lov_dbs.lookup_code
AND 'CST_BASIS' = lov_dbs.lookup_type
AND owh.resource_id = cdo.overhead_id
AND cdo.department_id = dept.department_id
AND owh.organization_id = 104
AND owh.cost_element_id = 5 -- Element
AND cdo.cost_type_id = 3 --Cost Type
ORDER BY 1, 2, 6;