You can use multiset
to generate rows as per the headcount
column as follows:
SELECT
HAP.NAME POSITION_TITLE,
HAP.POSITION_CODE,
PGF.NAME GRADE_NAME,
PGF.GRADE_CODE,
HAP.ACTIVE_STATUS,
HAP.POSITION_TYPE,
HAP.HEADCOUNT,
PAAM.ASSIGNMENT_NUMBER,
Lvls.Column_value row_num
FROM
HR_ALL_POSITIONS_F_VL HAP,
PER_GRADES_F_VL PGF,
PER_ALL_ASSIGNMENTS_M PAAM,
table(cast(multiset(select level from dual connect by level <= hap.headcount) as sys.OdciNumberList)) lvls
WHERE
HAP.ENTRY_GRADE_ID = PGF.GRADE_ID
AND PAAM.POSITION_ID(+) = HAP.POSITION_ID
AND TRUNC(Sysdate) between HAP.effective_start_date AND HAP.effective_end_date
AND TRUNC(Sysdate) between PGF.effective_start_date AND PGF.effective_end_date
AND PAAM.effective_start_date(+) <= TRUNC(Sysdate)
AND PAAM.effective_end_date(+) >= TRUNC(Sysdate);
Note: add the condition as per your requirement and always use standard ANSI joins.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…