Mastering SQL for Oracle Fusion HCM – Chapter 16. Best Practices for SQL in Fusion HCM – Optimizing Reports and Queries

 

Chapter 16. Best Practices for SQL in Fusion HCM – Optimizing Reports and Queries

Best Practices for Writing SQL in Oracle Fusion HCM

Discover expert tips and best practices for writing optimized, efficient, and scalable SQL queries in Oracle Fusion HCM, including real-world reporting advice.


🔹 Introduction

Writing SQL for Oracle Fusion HCM is not just about getting the correct results — it's about making sure your queries are performant, scalable, readable, and aligned with Oracle’s architecture. This chapter outlines best practices for:

  • Query design

  • Performance optimization

  • Data accuracy

  • Security and scalability

  • Common real-time mistakes to avoid


🔹 1. Always Use Effective Date Filters

Fusion HCM uses date-effective tables. Without proper filtering, you may retrieve duplicate or outdated data.

✅ Best Practice:


WHERE trunc(SYSDATE) BETWEEN effective_start_date AND effective_end_date

💡 Why:

Ensures you’re always working with currently valid records.


🔹 2. Avoid SELECT *

Fetching all columns reduces performance and increases load time.

❌ Bad:


SELECT *
FROM   per_all_people_f; 

✅ Good:


SELECT person_id,
       full_nameFROM   per_all_people_f

🔹 3. Use Indexed Columns in Filters and Joins

Common indexed columns in Fusion HCM:

  • person_id

  • assignment_id

  • effective_start_date

  • job_id

These accelerate query execution on large datasets.


🔹 4. Use Aliases for Readability

Improve query clarity and maintainability by using table aliases.

SELECT p.person_number,
       a.assignment_id
FROM   per_all_people_f p,
       per_all_assignments_m a
WHERE  p.person_id = a.person_id 

🔹 5. Use CASE for Business Logic

Convert business rules directly into SQL using CASE.


CASE WHEN salary > 100000 THEN 'Executive' ELSE 'Staff' END AS employee_category 

🔹 6. Avoid Subqueries in SELECT Clause When Possible

Subqueries in SELECT cause row-by-row evaluation, which is slow.

Instead, use joins with ROWNUM, RANK(), or ROW_NUMBER() when needed.


🔹 7. Leverage Common Table Expressions (CTEs)

CTEs improve readability for complex logic.


WITH active_emps
     AS (SELECT person_id
         FROM   per_all_assignments_m
         WHERE  assignment_status_type = 'ACTIVE')
SELECT full_name
FROM   per_all_people_f
WHERE  person_id IN (SELECT person_id
                     FROM   active_emps) 

🔹 8. Limit Data in Development

When developing or testing:


FETCH first 100 ROWS only 
This prevents performance hits during testing.

🔹 9. Handle NULLs Correctly

Use NVL, COALESCE, or CASE to handle nulls gracefully in reports.

SELECT NVL(email_address, 'Not Provided')
FROM   per_email_addresses; 

 🔹 10. Always Validate Business Rules with Functional Teams

Before finalizing a report:

  • Validate join logic

  • Confirm derived metrics

  • Ensure filters match business expectations


🔹 11. Use Parameters Instead of Hardcoding

For reusability and flexibility in BI Publisher:


WHERE department_id = :P_DEPT_ID

🔹 12. Common Pitfalls to Avoid

MistakeFix It By
Missing effective date filtersUse TRUNC(SYSDATE) between dates
Using SELECT *List only required fields
Cross joins without conditionAlways use ON clause with JOIN
Comparing NULLs with =Use IS NULL or NVL functions
Ignoring performance implicationsUse indexed fields and optimize joins

🔹 Summary

✅ Apply date-effective filtering
✅ Avoid SELECT *, use indexes and aliases
✅ Handle NULLs correctly
✅ Use CASE, CTEs, and clean joins
✅ Test and validate business rules with real-time users


🔹 Next Steps



No comments:

Post a Comment