Overview: This SQL Query used to fetch Opened Purchase Order PO with Category descriptions and concatenated segments name in Oracle R12 Application.
select distinct pha.segment1 Po_number, pla.LINE_NUM, nvl(pha.CLOSED_CODE,'OPEN') PO_status, pla.creation_date, (select DESCRIPTION from mtl_categories_tl where CATEGORY_ID = pla.CATEGORY_ID and SOURCE_LANG = 'US' and LANGUAGE='US') category_description, (select CONCATENATED_SEGMENTS from gl_code_combinations_kfv where code_combination_id = pda.code_combination_id)CONCATENATED_SEGMENTS, (select APPS.GL_FLEXFIELDS_PKG.get_concat_description(50428,pda.code_combination_id) from dual)SEGMENTS_Name from po_headers_all pha, po_lines_all pla, po_distributions_all pda, gl_code_combinations gcc where pha.PO_HEADER_ID = pla.PO_HEADER_ID and pla.PO_LINE_ID = pda.PO_LINE_ID and pda.CODE_COMBINATION_ID = gcc.CODE_COMBINATION_ID AND NVL(pha.closed_code,'OPEN') ='OPEN' order by pha.segment1, pla.line_num;