✅ Chapter 6. SQL ORDER BY and Sorting Logic in Fusion HCM
SQL ORDER BY – Sorting Data in Oracle Fusion HCM
Learn how to use SQL ORDER BY for sorting Fusion HCM data. Includes ascending, descending, multi-column, and real-time BI Publisher report examples.
๐น Introduction
The ORDER BY
clause allows you to sort the results of a query by one or more columns. Sorting is essential in Fusion HCM when:
-
Generating employee lists alphabetically
-
Sorting payroll results by date or amount
-
Ensuring consistent layout in BI Publisher or Extract outputs
This chapter explains how to use ORDER BY
effectively in both simple and complex queries.
๐น Theoretical Concepts
๐ Syntax of ORDER BY
๐ Key Sorting Options
Keyword | Description | Example |
---|---|---|
ASC |
Ascending (default) | ORDER BY full_name ASC |
DESC |
Descending | ORDER BY hire_date DESC |
Multiple Columns |
Sort by priority | ORDER BY department_id, full_name |
Position |
Sort by column number | ORDER BY 1 (sort by first column in SELECT) |
๐น Fusion HCM Real-World Use Cases
✅ Example 1: Sort by Employee Name
✅ Example 2: Sort by Department and Employee
SELECT full_name,
hire_date
FROM PER_ALL_PEOPLE_F
ORDER BY hire_date DESC;
๐น Real-Time Scenario (Fusion HCM Reporting)
๐งพ Scenario:
“HR wants a report of active employees sorted by business unit, then by full name.”
✅ SQL Query:
๐ This output will group employees by business unit and sort them alphabetically.
๐น Practice Exercise
๐ก Task: Write a query to fetch all primary assignments for active employees, sorted by job ID (descending), then by assignment number (ascending).
SELECT assignment_number,
job_id,
person_id
FROM PER_ALL_ASSIGNMENTS_M
WHERE primary_flag = 'Y'
AND TRUNC(SYSDATE) BETWEEN effective_start_date AND effective_end_date
ORDER BY job_id DESC,
assignment_number ASC;
๐น Best Practices
-
Always use
ORDER BY
in BI Publisher reports to ensure consistent output layout. -
Avoid ordering by non-indexed columns in large data sets unless needed.
-
Use
NULLS FIRST
orNULLS LAST
in Oracle for better null sorting:
-
You can sort on expressions:
๐น Summary
✅ The ORDER BY
clause sorts query results for clear and structured output.
✅ You can sort by one or more columns, use ASC
/DESC
, and sort expressions.
✅ In Fusion HCM, use ORDER BY
to control report layouts, grouping, and business logic outputs.
✅ Sort by business unit, hire date, department, or person name based on context.
๐น Next Steps
-
Previous Chapter: Mastering SQL for Oracle Fusion HCM – Chapter 5: WHERE Clause in SQL
-
Next Chapter: Mastering SQL for Oracle Fusion HCM – Chapter 7. SQL Functions and Expressions in Fusion HCM
Tags: #SQLORDERBY
, #FusionHCM
, #SortedReports
, #BIReportLayout
, #OracleSQLTips
No comments:
Post a Comment