Monday, April 7, 2025

Aggregate Data Into a Single Column - using LISTAGG

 Use LISTAGG as a query expression, to string several rows into a single row, in a single column.

Syntax

The syntax for the LISTAGG function in Oracle/PLSQL is:

LISTAGG (measure_column [, 'delimiter'])
  WITHIN GROUP (order_by_clause) [OVER (query_partition_clause)]

Parameters or Arguments

measure_column
The column or expression whose values you wish to concatenate together in the result set. Null values in the measure_column are ignored.
delimiter
Optional. It is the delimiter to use when separating the measure_column values when outputting the results.
order_by_clause
It determines the order that the concatenated values (ie: measure_column) are returned.

Returns

The LISTAGG function returns a string value.

Example

The LISTAGG function can be used in Oracle/PLSQL.

Since this is a more complicated function to understand, let's look at an example that includes data to demonstrate what the function outputs.

If you had a products table with the following data:

product_idproduct_name
1001Bananas
1002Apples
1003Pears
1004Oranges

And then you executed a SELECT statement using the LISTAGG function:

SELECT LISTAGG(product_name, ', ') WITHIN GROUP (ORDER BY product_name) "Product_Listing"
FROM products;

You would get the following results:

Product_Listing
Apples, Bananas, Oranges, Pears

In this example, the results of the LISTAGG function are output in a single field with the values comma delimited.

You can change the ORDER BY clause to use the DESC keyword and change the SELECT statement as follows:

SELECT LISTAGG(product_name, ', ') WITHIN GROUP (ORDER BY product_name DESC) "Product_Listing"
FROM products;

This would give the following results:

Product_Listing
Pears, Oranges, Bananas, Apples

You could change the delimiter from a comma to a semi-colon as follows:

SELECT LISTAGG(product_name, '; ') WITHIN GROUP (ORDER BY product_name DESC) "Product_Listing"
FROM products;

This would change your results as follows:

Product_Listing
Pears; Oranges; Bananas; Apples

In Query Expression, you can add this LISTAGG function.

The below is an example for the Vendor Address phone number table in PeopleSoft FSCM. The intended desire is to display each SETID and VENDOR_ID on its own row, but only once per combination. Then we want a third field to put all phone numbers into a single column. If a vendor has 1 or 20 phone numbers, we just want one row of data, but list all phone numbers in the third field in our results.

Steps to produce this in PEOPLESOFT FSCM

  1. Create a new Query in Query Manager.
  2. Insert record VENDOR_ADDR_PHN.
    • The Effective Dated logic will be automatically added. This is fine.
  3. Select the following fields to be displayed: SETID and VENDOR_ID.
    • Use the checkboxes on the Query tab.
  4. Go to the Expressions tab.
  5. Create a new Expression that has the following (screenshot found later in this post):
    • Expression Type: Long Character
    • Aggregate Function: Turn this checkbox on.
    • Expression Text: LISTAGG(A.PHONE, ‘ , ‘) WITHIN GROUP (ORDER BY A.PHONE)
    • (If you are using this trick with other tables already added, be sure to use the proper alias and field name. Our example assumes the field PHONE is from record alias “A”.)
  6. Click OK, to save the new expression.
  7. Choose “Use as Field“, for our new expression.
    • This adds our new expression to the Fields tab.
  8. Modify any heading text on the Fields tab.
  9. Run to view results.
  10. You should find that each SETID and VENDOR_ID have their own row, with the third field (Phone) having 1 or more phone numbers, separated by commas.

Bonus

You can also try out this Expression Text. It adds the Phone Type.

LISTAGG(A.PHONE_TYPE %CONCAT ':' %CONCAT A.PHONE, ' , ') WITHIN GROUP (ORDER BY A.PHONE_TYPE %CONCAT ':' %CONCAT A.PHONE)

Results

PeopleSoft Campus Community Tables

Person

PS_PERSONCore person data including birth and death information
PS_PERS_DATA_EFFDTCore person data history includes martial status and gender
PS_PERSONAL_DATASnapshot bio/demo data
PS_PER_POI_TYPEPerson of Interest (POI) Type
PS_PER_POI_TRANSPerson of Interest (POI) History

Identification

  
PS_CITIZENSHIPCitizenship data
PS_SCC_CITIZ_HISTCitizenship history
PS_CITIZEN_PSSPRTCitizenship passport data
PS_DIVERS_ETHNICITYEthnicity data
PS_DIVERSITYEthnicity diversity data
PS_PERS_NIDNational ID data
PS_EXTERNAL_SYSKEYExternal system data (key)
PS_EXTERNAL_SYSTEMExternal system data
PS_PER_ORG_ASGNOrganisational relationships
PS_SCC_PERSON_AUSAustralian Tax File Number Data
PS_SCC_CHESSN_AUSAustralian CHESSN Data

Biographic/Demographic

PS_ADDRESSESAddress history
PS_EMAIL_ADDRESSESEmail addresses
PS_NAMESNames history
PS_PERSONAL_PHONEPhone & Fax data

3Cs (Communications, Checklists and Comments)

PS_COMMUNICATIONCommunication data
PS_PERSON_CHECKLSTChecklist data
PS_PERSON_COMMENTComment data
PS_VAR_DATA_[AF]Variable data. Replace [AF] with administrative function e.g. SPRG
PS_LAST_3CS_TBLTracks the last SEQ_3C value for a student

Campus Event Planning (and Meetings)

PS_CAMPUS_EVENTCampus Event
PS_EVENT_MTGCampus Event Meeting

Service Indicators

PS_SRVC_IND_DATAService indicator data
PS_SRVC_IN_RSN_TBLService indicator reason
PS_AUDIT_SRVC_INDService indicator audit

Curriculum Management

Course data

PS_CRSE_CATALOGCourse catalog
PS_CRSE_COMPONENTCourse components
PS_CRSE_OFFERCourse offerings
PS_CRSE_EQUIV_TBLCourse equivalencies
PS_CRSE_LST_HDR_SFCourse list header
PS_CRSE_LST_DTL_SFCourse list details
PS_CRSE_TOPICSCourse topics

Class data

PS_CLASS_TBLClass data
PS_CLASS_ASSOCClass associations
PS_CLASS_ATTENDNCEClass attendance
PS_CLASS_COMPONENTClass components
PS_CLASS_INSTRClass instructors
PS_CLASS_MTG_PATClass meeting patterns
PS_CLASS_NOTESClass notes

Records and Enrolment

Term Activation and History

PS_STDNT_CAREERStudent career
PS_STDNT_CAR_TERMStudent career term activation
PS_SSR_HECS_ELECAustralian-specific HECS Loan Election
PS_STDNT_SESSIONStudent session
PS_TRNS_CRSE_SCHTransfer credit school
PS_TRNS_CRSE_TERMTransfer credit course term
PS_TRNS_OTHR_MODELOther transfer credits model
PS_TRNS_OTHR_TERMOther transfer credits term
PS_TRNS_TEST_MODELTest transfer credits model
PS_TRNS_TEST_TERMTest transfer credits term

Program/Plan

PS_ACAD_PROGStudent program data
PS_ACAD_PLANStudent plan data
PS_SSR_ACADPRG_AUSAustralian-specific student program data

Enrolment

PS_STDNT_ENRLStudent enrolments
PS_CLASS_TBL_SE_VWView that combines student enrolment & class setup data
PS_SSR_STDENRL_AUSAustralian-specific student enrolment data
PS_ENRL_REQ_HEADEREnrolment request header
PS_ENRL_REQ_DETAIEnrolment request detail
PS_SSR_STDENRL_AUSAustralian Student Enrolment data

Graduation/Degrees

PS_ACAD_DEGRStudent degree data
PS_ACAD_DEGR_PLANStudent degree plan data
PS_ACAD_DEGR_HONSStudent degree honours data

Student Groups

PS_STDNT_GRPSStudent group data
PS_STDNT_GRPS_HISTStudent group history

Grade Book

PS_STDNT_GRADE_DTLStudent's grades detail
PS_LAM_CLASS_ACTVClass assignments information

Set Up SACR

Institution structure

PS_INSTITUTION_TBLInstitution setup
PS_CAMPUS_TBLCampus setup
PS_CAMPUS_LOC_TBLCampus location setup
PS_HOME_CAMPUS_TBLHome campus setup
PS_ACAD_GROUP_TBLAcademic group setup
PS_ACAD_ORG_TBLAcademic organisation setup
PS_SSR_ACD_ORG_AUSAustralian-specific Academic organisation setup

Academic career

PS_ACAD_CAR_TBLAcademic career setup
PS_ACAD_CAR_PTRSAcademic career pointers setup
PS_CATLG_CAR_TBLAcademic career level setup
PS_ACAD_CAL_TABLEAcademic career calendar setup
PS_HOLIDAY_TBLHoliday setup

Programs, Plans and Degrees

PS_ACAD_PROG_TBLAcademic program setup
PS_ACAD_PROG_OWNERAcademic program owner setup
PS_SSR_ACD_PRG_AUSAustralian-specific academic program setup
PS_SSR_PRG_CD_TBLAcademic program code setup
PS_ACAD_PLAN_TBLAcademic plan setup
PS_DEGREE_TBLDegree setup
PS_SSR_ACDPRGT_AUSAustralian Academic Program TAC setup
PS_SSR_ACD_PLN_AUSAustralian Academic Plan setup

Term and Session

PS_TERM_TBLTerm setup
PS_TERM_VAL_TBLTerm Values
PS_SESSION_TBLTerm session setup
PS_SESS_TIME_PERODSession time periods

Load/Level Rules

PS_LVL_LD_RULE_TBLAcademic level/load rules setup
PS_ACAD_LEVEL_TBLAcademic level setup
PS_ACAD_LOAD_TBLAcademic load setup
PS_ACAD_LOAD2_TBLAcademic load for statistics setup
PS_SSR_LVLLOAD_AUSAustralian specific load/level rules setup
PS_SSR_ACADLOD_AUSAustralian Academic Load setup

Grading

PS_GRADE_TBLGrade setup
PS_GRADE_BASIS_TBLGrading basis setup
PS_GRD_BASE_CHOICEGrading basis choice setup
PS_GRADESCHEME_TBLGrading scheme setup
PS_SSR_GRADE_FLAGGrading flag setup

Security

Student Records Security

PS_SCRTY_TBL_INSTInstitution security
PS_SCRTY_TBL_ACADAcademic organisation security
PS_SCRTY_TBL_CARAcademic career security
PS_SCRTY_TBL_PLANAcademic plan security
PS_SCRTY_TBL_PROGAcademic program security
PS_SCRTY_ADM_ACTNAdmissions action security
PS_SCRTY_PROG_ACTNProgram action security
PS_SCRTY_APPL_CTRApplication centre security
PS_SCRTY_RECR_CTRRecruiting centre security
PS_OPR_GRP_3C_TBL3Cs operator group security
PS_ENRL_ACCESS_GRPEnrolment access group security
PS_ENRMT_OVRD_TBLEnrolment override security by enrolment access ID
PS_SCRTY_TBL_SRVCService indicator security
PS_SCRTY_TSCRPTTranscript type security
PS_SAD_TEST_SCTYTest ID security

Student Financials Security

PS_SEC_ISET_OPROperator Institution set security
PS_SEC_UNITSF_OPROperator Business unit security
PS_SEC_SETID_OPROperator SetID security

Student Admissions/Recruiting

Applicants

PS_ADM_APP_CAR_SEQApplication career sequence (stores next available career nbr)
PS_ADM_APPL_DATAApplication data
PS_ADM_APPL_PLANApplication plan
PS_ADM_APPL_PROGApplication program
PS_SAD_APL_PRG_AUSAustralian-specific application program data
PS_ADM_APPL_RCR_CARecruiting category

Prospects

PS_ADM_PRSPCT_CARProspect career
PS_ADM_PRSPCT_PLANProspect plan
PS_ADM_PRSPCT_PROGProspect program

Student Financials

Accounts

PS_ACCOUNT_SFStudent account
PS_ITEM_SFStudent account items
PS_ITEM_LINE_SFStudent account item lines
PS_ITEM_XREFStudent item cross reference
PS_PAYMENT_TBLStudent payments
PS_QUICK_POST_TBLQuick post setup
PS_QUICK_POST_ERRQuick post errors
PS_ADM_APPL_DEPCalculated deposit fees (e.g. student housing, tuition deposit) as distinct from full charges

Billing

BI_BILL_HEADERBilling Invoice Header
BI_BILLING_LINEBilling Line
BI_BILL_MESSAGEBill Messages
BI_STD_REQ_TBLBilling Standard Request Table
BI_BILL_ERRORBilling Errors

Credit History and Collections

PS_CREDIT_HISTORYStudent Credit history
PS_COLLECTION_SFStudent collections
PS_COLL_LTR_ITEMDunning/collection letters
PS_COLLECT_EFFORTStudent collections recovery effort data

Cashiering

CSH_BD_CSH_TBLBusiness Date Cashier Table
CSH_BD_CSH_OPENBusiness Date Cashier Open Table
CSH_BD_REG_OPENBusiness Date Register Open Table
CSH_BD_REG_TBLBusiness Date Register Table
CSH_OFF_RECEIPTCashier Office Receipts
CSH_OFF_RCPT_LCashier Office Receipt Line
CSH_OFF_RCPT_TCashier Office Receipt Tender
CSH_OFF_TBLCashiering Office Table

GL Interface

SF_ACCTG_LNSF Accounting Line
SF_ACCTG_ERRORSF Quick Posting Error Table

Group Post

GROUP_CONT_INFOControl Group Info
GROUP_LINEGroup Line Information/Check

Item Types

ITEM_TYPE_TBLItem Type Table
ITEM_ACCT_TYPEValid Account Types
GL_INTERFACEGeneral Ledger Interface

Optional Fees

OPT_FEE_STDNTOptional Fees by Student
OPT_FEE_TBLOptional Fees Table
OPT_FEE_TERMOptional Fee Terms
OPT_FEE_VALOptional Fee Values

Refunds

REFUND_HDRRefund Header
REFUND_DTLRefund Detail
REFUND_CHECKRefund Check Information
REFUND_WLRefund Work List

Term Fee Setup

TERM_FEE_TBLTerm Fee Table
TERM_FE_CD_TBLTerm Fee Code Table
TERM_SF_CD_TBLTerm Sub Fee Code Table
TERM_SUBFEE_TBLTerm Sub Fee Table

Third Party Contracts (TPCs) / Deferral Contracts / Payment Plans

TP_CHARGESThird Party Allowable Charges
TP_CONTRACTThird Party Contracts
TP_STUDENTThird Party Student
TP_STDNT_CHRGThird Party Allowable Charges Student

Tuition Calc

TUIT_CALC_TBLTuition Calc Table
CALC_MESSAGESTuition Calc Error/Warn Messages
OPT_FEE_STDNTOptional Fees by Student

Tuition Group Setup

SEL_GROUP_TBLSelector Group Table
SEL_GROUP_CRITRSelector Group Criteria
GROUP_FEE_TBLGroup Fee Table

Tuition Group Criteria Setup

SEL_CRITER_TBLGroup Selector Criteria
SEL_CRITR_TBLGroup Selector Criteria
SEL_VALUE_TBLSelector Values Table

Waiver Setup

WAIVER_CODE_TBLWaiver Code Table
WAIVER_GRP_DTLWaiver Group Detail Table
WAIVER_GRP_TBLWaiver Group Table
WAIVER_TBLWaver Table

1098-T Reporting

SF_1098_DTL_SFSF 1098T Detail Record
SF_1098_ITEMSF 1098T Item Details


Aggregate Data Into a Single Column - using LISTAGG

  Use LISTAGG as a query expression, to string several rows into a single row, in a single column. Syntax The syntax for the LISTAGG functio...