--ebs 分类账与法人主体对应关系
SELECT A.SET_OF_BOOKS_ID LEDGER_ID,
GL.NAME LEDGER_NAME,
GL.CURRENCY_CODE,
FFV.FLEX_VALUE OU_CODE,
A.NAME OU_NAME,
A.ORGANIZATION_ID,
A.DEFAULT_LEGAL_CONTEXT_ID,
B.FLEX_SEGMENT_VALUE,
FFV.FLEX_VALUE COMPANY_CODE,
FFV.DESCRIPTION COMPANY_NAME
FROM HR_OPERATING_UNITS A,
GL_LEGAL_ENTITIES_BSVS B,
FND_FLEX_VALUES_VL FFV,
FND_FLEX_VALUE_SETS FFS,
GL_LEDGERS GL
WHERE A.DEFAULT_LEGAL_CONTEXT_ID = B.LEGAL_ENTITY_ID
AND B.FLEX_SEGMENT_VALUE = FFV.FLEX_VALUE
AND FFV.FLEX_VALUE_SET_ID = FFS.FLEX_VALUE_SET_ID
AND FFS.FLEX_VALUE_SET_NAME = 'NM_GL_COM'
AND A.SET_OF_BOOKS_ID = GL.LEDGER_ID;
--法人
select HOU.set_of_books_id AS LEDGER_ID,
hou.organization_id,
hou.name AS OU_NAME,
xep.legal_entity_id AS LEGAL_ID,
xep.legal_entity_identifier AS LEGAL_CODE,
xep.name AS LEGAL_NAME
from hr_operating_units hou, xle_entity_profiles xep
where hou.set_of_books_id = '2021'
and hou.default_legal_context_id = xep.legal_entity_id
order by xep.legal_entity_identifier;