-Get The Parent Position Base on Child Position ID
all Related to
HRMS =>work Stricture => Position => Position hierarchy Form.
---------------
CREATE OR REPLACE FUNCTION XX_GET_MGR_POS
(PChildPosId NUMBER,
PBg NUMBER,
)
RETURN NUMBER
AS
v_mgr_pos NUMBER;
BEGIN
BEGIN
SELECT PARENT_POSITION_ID
INTO V_MGR_POS
FROM (SELECT HAP.NAME PARENT_NAME,
PSE.PARENT_POSITION_ID,
-------------------------------------
HAS.NAME CHILD_NAME,
PSE.SUBORDINATE_POSITION_ID,
------------------------------------
ROWNUM LVL
FROM (SELECT NAME, POSITION_ID
FROM HR_ALL_POSITIONS_F_TL
WHERE LANGUAGE = USERENV ('LANG')) HAP,
(SELECT NAME, POSITION_ID
FROM HR_ALL_POSITIONS_F_TL
WHERE LANGUAGE = USERENV ('LANG')
AND POSITION_ID = PChildPosId) HAS,
PER_POS_STRUCTURE_ELEMENTS PSE,
PER_POS_STRUCTURE_VERSIONS PVE,
PER_POSITION_STRUCTURES PPS
WHERE 1 = 1
AND PSE.BUSINESS_GROUP_ID = PBg
AND PVE.POSITION_STRUCTURE_ID =
PPS.POSITION_STRUCTURE_ID
AND PSE.POS_STRUCTURE_VERSION_ID =
PVE.POS_STRUCTURE_VERSION_ID
AND SYSDATE BETWEEN PVE.DATE_FROM
AND NVL (PVE.DATE_TO, SYSDATE)
AND HAP.POSITION_ID = PSE.PARENT_POSITION_ID
AND HAS.POSITION_ID = PSE.SUBORDINATE_POSITION_ID)
WHERE UPPER (PARENT_NAME) LIKE '%MANAGER%';
EXCEPTION
WHEN NO_DATA_FOUND
THEN
-------------------if no position then get the CEO upper the Position From Parameter--------------- BEGIN
SELECT PARENT_POSITION_ID
INTO V_MGR_POS
FROM (SELECT HAP.NAME PARENT_NAME,
PSE.PARENT_POSITION_ID,
HAS.NAME CHILD_NAME,
PSE.SUBORDINATE_POSITION_ID,
ROWNUM LVL
FROM (SELECT NAME, POSITION_ID
FROM HR_ALL_POSITIONS_F_TL
WHERE LANGUAGE = USERENV ('LANG')) HAP,
(SELECT NAME, POSITION_ID
FROM HR_ALL_POSITIONS_F_TL
WHERE LANGUAGE = USERENV ('LANG')
AND POSITION_ID = PChildPosId) HAS,
PER_POS_STRUCTURE_ELEMENTS PSE,
PER_POS_STRUCTURE_VERSIONS PVE,
PER_POSITION_STRUCTURES PPS
WHERE 1 = 1
AND PSE.BUSINESS_GROUP_ID = PBG
AND PVE.POSITION_STRUCTURE_ID =
PPS.POSITION_STRUCTURE_ID
AND PSE.POS_STRUCTURE_VERSION_ID =
PVE.POS_STRUCTURE_VERSION_ID
AND SYSDATE BETWEEN PVE.DATE_FROM
AND NVL (PVE.DATE_TO, SYSDATE)
AND HAP.POSITION_ID = PSE.PARENT_POSITION_ID
AND HAS.POSITION_ID = PSE.SUBORDINATE_POSITION_ID)
WHERE UPPER (PARENT_NAME) LIKE '%CEO%';
END;
END;
RETURN V_MGR_POS;
EXCEPTION
WHEN OTHERS
THEN
RETURN 0;
END;
-----------------------------------------------------------------------
SELECT XX_GET_MGR_POS (6419, 81) FROM DUAL
-----------------------------------------------------------------------