Thursday, 25 June 2020

Oracle Cloud + Query to get The Data Access for an User

7 comments
SELECT USERNAME,PERSON_NUMBER,person_name,ROLE_NAME,ROLE_CODE,SECURITY_CONTEXT ,SECURITY_CONTEXT_VALUE
FROM(
SELECT
 PU.USERNAME ,
 papf.person_number,
 ppnf.display_name person_name,
 rtl.role_name,
 ROLE.ROLE_NAME ROLE_CODE,
 'DATA ACCESS SET' security_context,
 GL.NAME security_context_value
 FROM
 fusion.fun_user_role_data_asgnmnts role,
 fusion.gl_access_sets gl,
 fusion.per_users pu,
 per_all_people_f papf,
 per_person_names_f_v ppnf,
 ase_role_b r,
 ase_role_tl rtl
WHERE
 GL.ACCESS_SET_ID = ROLE.ACCESS_SET_ID
 AND PU.USER_GUID = ROLE.USER_GUID
 AND ROLE.ROLE_NAME=R.CODE
 AND nvl(pu.suspended,'N') = 'N'
 AND pu.person_id=papf.person_id
 AND nvl(papf.effective_start_date,sysdate) <= sysdate
 AND nvl(papf.effective_end_date,sysdate) >= sysdate
 AND papf.person_id=ppnf.person_id
 AND nvl(ppnf.effective_start_date,sysdate) <= sysdate
 AND nvl(ppnf.effective_end_date,sysdate) >= sysdate
 AND r.role_id = rtl.role_id
 AND rtl.language = 'US'
 AND nvl(r.effective_start_date,sysdate) <= sysdate
 AND nvl(r.effective_end_date,sysdate) >= sysdate
 AND pu.active_flag = 'Y'
UNION
SELECT
 PU.USERNAME,
 papf.person_number,
 ppnf.display_name person_name,
 rtl.role_name,
 ROLE.ROLE_NAME ROLE_CODE,
 'BUSINESS UNIT' security_context,
 BU.BU_NAME security_context_value
FROM
 fusion.fun_all_business_units_v bu,
 fusion.fun_user_role_data_asgnmnts role,
 fusion.per_users pu,
 per_all_people_f papf,
 per_person_names_f_v ppnf,
 ase_role_b r,
 ase_role_tl rtl
WHERE
 ROLE.ORG_ID = BU.BU_ID
 AND PU.USER_GUID = ROLE.USER_GUID
 AND ROLE.ROLE_NAME=R.CODE
 AND r.role_id = rtl.role_id
 AND rtl.language = 'US'
 AND nvl(pu.suspended,'N') = 'N'
 AND pu.person_id=papf.person_id
 AND nvl(papf.effective_start_date,sysdate) <= sysdate
 AND nvl(papf.effective_end_date,sysdate) >= sysdate
  AND papf.person_id=ppnf.person_id
  AND nvl(ppnf.effective_start_date,sysdate) <= sysdate
 AND nvl(ppnf.effective_end_date,sysdate) >= sysdate
 AND nvl(r.effective_start_date,sysdate) <= sysdate and
     nvl(r.effective_end_date,sysdate) >= sysdate
 AND pu.active_flag = 'Y'
UNION
SELECT
 pu.username,
 papf.person_number,
 ppnf.display_name person_name,
 rtl.role_name,
 role.role_name role_code,
 'LEDGERS' security_context,
 led.name security_context_value
FROM
 fusion.gl_ledgers led,
 fusion.fun_user_role_data_asgnmnts role,
 fusion.per_users pu,
 per_all_people_f papf,
 per_person_names_f_v ppnf,
 ase_role_b r,
 ase_role_tl rtl
WHERE
 role.ledger_id = led.ledger_id
 and pu.user_guid = role.user_guid
 and role.role_name=r.code
 AND r.role_id = rtl.role_id
 AND rtl.language = 'US'
 AND nvl(r.effective_start_date,sysdate) <= sysdate and
     nvl(r.effective_end_date,sysdate) >= sysdate
 AND nvl(pu.suspended,'N') = 'N'
 AND pu.person_id=papf.person_id
 AND nvl(papf.effective_start_date,sysdate) <= sysdate
 AND nvl(papf.effective_end_date,sysdate) >= sysdate
  AND papf.person_id=ppnf.person_id
  AND nvl(ppnf.effective_start_date,sysdate) <= sysdate
 AND nvl(ppnf.effective_end_date,sysdate) >= sysdate
 AND pu.active_flag = 'Y'
UNION
SELECT
 pu.username,
 papf.person_number,
 ppnf.display_name person_name,
 rtl.role_name,
 role.role_name role_code,
 'ASSET BOOK' security_context,
 book.book_type_name security_context_value
FROM
 FUSION.FUN_USER_ROLE_DATA_ASGNMNTS ROLE,
 FUSION.FA_BOOK_CONTROLS BOOK,
 FUSION.PER_USERS PU,
 per_all_people_f papf,
 per_person_names_f_v ppnf,
 ase_role_b r,
 ase_role_tl rtl
WHERE
 BOOK.BOOK_CONTROL_ID = ROLE.BOOK_ID
 AND PU.USER_GUID = ROLE.USER_GUID
 AND ROLE.ROLE_NAME=R.CODE
 AND r.role_id = rtl.role_id
 AND rtl.language = 'US'
 AND nvl(r.effective_start_date,sysdate) <= sysdate and
     nvl(r.effective_end_date,sysdate) >= sysdate
 AND nvl(pu.suspended,'N') = 'N'
 AND pu.person_id=papf.person_id
 AND nvl(papf.effective_start_date,sysdate) <= sysdate
 AND nvl(papf.effective_end_date,sysdate) >= sysdate
  AND papf.person_id=ppnf.person_id
  AND nvl(ppnf.effective_start_date,sysdate) <= sysdate
 AND nvl(ppnf.effective_end_date,sysdate) >= sysdate
 AND pu.active_flag = 'Y'
UNION
SELECT
pu.username,
 papf.person_number,
 ppnf.display_name person_name,
 rtl.role_name,
 role.role_name role_code,
 'INTERCOMPANY ORGANIZATION' security_context,
 INTERCO.INTERCO_ORG_NAME security_context_value
FROM
 fusion.fun_user_role_data_asgnmnts role,
 fusion.fun_interco_organizations interco,
 fusion.per_users pu,
 per_all_people_f papf,
 per_person_names_f_v ppnf,
 ase_role_b r,
 ase_role_tl rtl
WHERE
 INTERCO.INTERCO_ORG_ID = ROLE.INTERCO_ORG_ID
 AND PU.USER_GUID = ROLE.USER_GUID
  AND ROLE.ROLE_NAME=R.CODE
 AND r.role_id = rtl.role_id
 AND rtl.language = 'US'
 AND nvl(r.effective_start_date,sysdate) <= sysdate and
     nvl(r.effective_end_date,sysdate) >= sysdate
 AND nvl(pu.suspended,'N') = 'N'
 AND pu.person_id=papf.person_id
 AND nvl(papf.effective_start_date,sysdate) <= sysdate
 AND nvl(papf.effective_end_date,sysdate) >= sysdate
  AND papf.person_id=ppnf.person_id
  AND nvl(ppnf.effective_start_date,sysdate) <= sysdate
 AND nvl(ppnf.effective_end_date,sysdate) >= sysdate
 AND pu.active_flag = 'Y'
UNION
SELECT
pu.username,
 papf.person_number,
 ppnf.display_name person_name,
 rtl.role_name,
 role.role_name role_code,
 'COST ORGANIZATION' security_context,
 COST.COST_ORG_NAME security_context_value
FROM
 FUSION.FUN_USER_ROLE_DATA_ASGNMNTS ROLE,
 FUSION.CST_COST_ORGS_V COST,
 FUSION.PER_USERS PU,
  per_all_people_f papf,
  per_person_names_f_v ppnf,
  ase_role_b r,
 ase_role_tl rtl
WHERE
 COST.COST_ORG_ID = ROLE.CST_ORGANIZATION_ID
 AND PU.USER_GUID = ROLE.USER_GUID
  AND ROLE.ROLE_NAME=R.CODE
 AND r.role_id = rtl.role_id
 AND rtl.language = 'US'
 AND nvl(r.effective_start_date,sysdate) <= sysdate and
     nvl(r.effective_end_date,sysdate) >= sysdate
 AND nvl(pu.suspended,'N') = 'N'
 AND pu.person_id=papf.person_id
 AND nvl(papf.effective_start_date,sysdate) <= sysdate
 AND nvl(papf.effective_end_date,sysdate) >= sysdate
  AND papf.person_id=ppnf.person_id
  AND nvl(ppnf.effective_start_date,sysdate) <= sysdate
 AND nvl(ppnf.effective_end_date,sysdate) >= sysdate
 AND pu.active_flag = 'Y'
UNION
SELECT
pu.username,
 papf.person_number,
 ppnf.display_name person_name,
 rtl.role_name,
 role.role_name role_code,
 'MANUFACTURING PLANT' security_context,
 MFG.DEF_SUPPLY_SUBINV security_context_value
FROM
 FUSION.FUN_USER_ROLE_DATA_ASGNMNTS ROLE,
 FUSION.RCS_MFG_PARAMETERS MFG,
 FUSION.PER_USERS PU,
 per_all_people_f papf,
 per_person_names_f_v ppnf,
  ase_role_b r,
 ase_role_tl rtl
WHERE
 MFG.ORGANIZATION_ID = ROLE.MFG_ORGANIZATION_ID
 AND PU.USER_GUID = ROLE.USER_GUID
  AND ROLE.ROLE_NAME=R.CODE
 AND r.role_id = rtl.role_id
 AND rtl.language = 'US'
 AND nvl(r.effective_start_date,sysdate) <= sysdate and
     nvl(r.effective_end_date,sysdate) >= sysdate
 AND nvl(pu.suspended,'N') = 'N'
 AND pu.person_id=papf.person_id
 AND nvl(papf.effective_start_date,sysdate) <= sysdate
 AND nvl(papf.effective_end_date,sysdate) >= sysdate
  AND papf.person_id=ppnf.person_id
  AND nvl(ppnf.effective_start_date,sysdate) <= sysdate
 AND nvl(ppnf.effective_end_date,sysdate) >= sysdate
 AND pu.active_flag = 'Y'
UNION
SELECT
pu.username,
 papf.person_number,
 ppnf.display_name person_name,
 rtl.role_name,
 role.role_name role_code,
 'CONTROL BUDGET' security_context,
 BUDGET.NAME security_context_value
FROM
 FUSION.FUN_USER_ROLE_DATA_ASGNMNTS ROLE,
 FUSION.XCC_CONTROL_BUDGETS BUDGET,
 FUSION.PER_USERS PU,
  per_all_people_f papf,
  per_person_names_f_v ppnf,
  ase_role_b r,
 ase_role_tl rtl
WHERE
 BUDGET.CONTROL_BUDGET_ID = ROLE.CONTROL_BUDGET_ID
 AND PU.USER_GUID = ROLE.USER_GUID
  AND ROLE.ROLE_NAME=R.CODE
 AND r.role_id = rtl.role_id
 AND rtl.language = 'US'
 AND nvl(r.effective_start_date,sysdate) <= sysdate and
     nvl(r.effective_end_date,sysdate) >= sysdate
 AND nvl(pu.suspended,'N') = 'N'
 AND pu.person_id=papf.person_id
 AND nvl(papf.effective_start_date,sysdate) <= sysdate
 AND nvl(papf.effective_end_date,sysdate) >= sysdate
  AND papf.person_id=ppnf.person_id
  AND nvl(ppnf.effective_start_date,sysdate) <= sysdate
 AND nvl(ppnf.effective_end_date,sysdate) >= sysdate
 AND pu.active_flag = 'Y'
UNION
SELECT
pu.username,
 papf.person_number,
 ppnf.display_name person_name,
 rtl.role_name,
 role.role_name role_code,
 'REFERENCE DATA SET' security_context,
 ST.SET_NAME security_context_value
FROM
 FUSION.FUN_USER_ROLE_DATA_ASGNMNTS ROLE,
 FUSION.FND_SETID_SETS_VL ST,
 FUSION.PER_USERS PU,
 per_all_people_f papf,
 per_person_names_f_v ppnf,
  ase_role_b r,
 ase_role_tl rtl
WHERE
 ST.SET_ID = ROLE.SET_ID
 AND PU.USER_GUID = ROLE.USER_GUID
  AND ROLE.ROLE_NAME=R.CODE
 AND r.role_id = rtl.role_id
 AND rtl.language = 'US'
 AND nvl(r.effective_start_date,sysdate) <= sysdate and
     nvl(r.effective_end_date,sysdate) >= sysdate
 AND nvl(pu.suspended,'N') = 'N'
 AND pu.person_id=papf.person_id
 AND nvl(papf.effective_start_date,sysdate) <= sysdate
 AND nvl(papf.effective_end_date,sysdate) >= sysdate
  AND papf.person_id=ppnf.person_id
  AND nvl(ppnf.effective_start_date,sysdate) <= sysdate
 AND nvl(ppnf.effective_end_date,sysdate) >= sysdate
 AND pu.active_flag = 'Y'
UNION
SELECT
pu.username,
 papf.person_number,
 ppnf.display_name person_name,
 rtl.role_name,
 role.role_name role_code,
 'INVENTORY ORGANIZATION' security_context,
 INV.ORGANIZATION_CODE security_context_value
FROM
 FUSION.FUN_USER_ROLE_DATA_ASGNMNTS ROLE,
 FUSION.INV_ORG_PARAMETERS INV,
 FUSION.PER_USERS PU,
 per_all_people_f papf,
 per_person_names_f_v ppnf,
  ase_role_b r,
 ase_role_tl rtl
WHERE
 INV.ORGANIZATION_ID = ROLE.INV_ORGANIZATION_ID
 AND PU.USER_GUID = ROLE.USER_GUID
  AND ROLE.ROLE_NAME=R.CODE
 AND r.role_id = rtl.role_id
 AND rtl.language = 'US'
 AND nvl(r.effective_start_date,sysdate) <= sysdate and
     nvl(r.effective_end_date,sysdate) >= sysdate
 AND nvl(pu.suspended,'N') = 'N'
 AND pu.person_id=papf.person_id
 AND nvl(papf.effective_start_date,sysdate) <= sysdate
 AND nvl(papf.effective_end_date,sysdate) >= sysdate
  AND papf.person_id=ppnf.person_id
  AND nvl(ppnf.effective_start_date,sysdate) <= sysdate
 AND nvl(ppnf.effective_end_date,sysdate) >= sysdate
 AND pu.active_flag = 'Y'
UNION
SELECT
pu.username,
 papf.person_number,
 ppnf.display_name person_name,
 rtl.role_name,
 role.role_name role_code,
 'PROJECT ORGANIZATION CLASSIFICATION' security_context,
 HR.CLASSIFICATION_CODE security_context_value
FROM
 FUSION.FUN_USER_ROLE_DATA_ASGNMNTS ROLE,
 FUSION.HR_ORG_UNIT_CLASSIFICATIONS_F HR,
 FUSION.PER_USERS PU,
  per_all_people_f papf,
  per_person_names_f_v ppnf,
  ase_role_b r,
 ase_role_tl rtl
WHERE
 HR.ORG_UNIT_CLASSIFICATION_ID = ROLE.ORG_ID
 AND PU.USER_GUID = ROLE.USER_GUID
  AND ROLE.ROLE_NAME=R.CODE
 AND r.role_id = rtl.role_id
 AND rtl.language = 'US'
 AND nvl(r.effective_start_date,sysdate) <= sysdate and
     nvl(r.effective_end_date,sysdate) >= sysdate
 AND nvl(pu.suspended,'N') = 'N'
 AND pu.person_id=papf.person_id
 AND nvl(papf.effective_start_date,sysdate) <= sysdate
 AND nvl(papf.effective_end_date,sysdate) >= sysdate
  AND papf.person_id=ppnf.person_id
  AND nvl(ppnf.effective_start_date,sysdate) <= sysdate
 AND nvl(ppnf.effective_end_date,sysdate) >= sysdate
 AND pu.active_flag = 'Y' 
 )
 WHERE username='aalam'
 ORDER BY USERNAME,ROLE_NAME,SECURITY_CONTEXT

Thanks
Amar Alam