select
pos.position_id,
pavb.employee_id,
pos.name pos_name,
emp.full_name,
bg.budget_group_id,
bg.short_name bg_name,
pkfv.CONCATENATED_SEGMENTS,
wlp.position_line_id pos_line_id,
PSB_PSBRPVPR_XMLP_PKG.CF_1FORMULA0090(bg.budget_group_id) CF_CURRENCY_CODE,
PSB_PSBRPVPR_XMLP_PKG.CP_CURRENCY_CODE_p CP_CURRENCY_CODE,
PSB_PSBRPVPR_XMLP_PKG.CP_ELEM_TOTAL_p CP_ELEM_TOTAL
from PSB_WORKSHEETS WS,
PSB_WS_LINES_POSITIONS WLP,
PSB_WS_POSITION_LINES WPL,
PSB_POSITIONS POS,
PSB_POSITION_DEFINITIONS_KFV PKFV,
PSB_POSITION_ASSIGNMENTS_V PAVB,
psb_employees emp ,
psb_budget_groups bg
where ws.worksheet_id = :p_worksheet_id
and nvl(pos.vacant_position_flag,'Y') = 'Y'
and WLP.Worksheet_ID = WS.Worksheet_ID
and WLP.Position_Line_ID = WPL.Position_Line_ID
and POS.Position_ID = WPL.Position_ID
and POS.POSITION_DEFINITION_ID = PKFV.POSITION_DEFINITION_ID
and pavb.position_id(+) = wpl.position_id
and PAVB.Assignment_Type(+) = 'EMPLOYEE'
and PAVB.Primary_Employee_Flag(+) = 'Y'
and emp.employee_id(+) = pavb.employee_id
and bg.budget_group_id = wpl.budget_group_id
ORDER BY 5 ASC,6 ASC ,7 asc,4 asc, 1 asc,2 asc, 3 asc,8 asc,bg.name , pkfv.concatenated_segments |