Mastering SQL for Oracle Fusion HCM – Chapter 7. SQL Functions and Expressions in Fusion HCM

 

✅ Chapter 7. SQL Functions and Expressions in Fusion HCM

SQL Functions in Oracle Fusion HCM – Date, String, Numeric

Learn key SQL functions (DATE, STRING, NUMBER, NULL) with real-time Fusion HCM examples. Build efficient queries for reporting, BI, and HDL validation.


๐Ÿ”น Introduction

SQL functions allow you to manipulate and transform data within your queries. In Oracle Fusion HCM, functions are essential when:

  • Formatting dates

  • Trimming strings

  • Handling null values

  • Creating custom columns in BI Publisher

  • Writing logic in value sets or HCM extracts

This chapter covers the most used built-in functions and how to apply them in Fusion HCM real-world queries.


๐Ÿ”น Categories of SQL Functions

๐Ÿ“† Date Functions

FunctionDescriptionExample
SYSDATECurrent dateSYSDATE
TRUNC(date)Remove timeTRUNC(SYSDATE)
ADD_MONTHS(date, n)Add monthsADD_MONTHS(hire_date, 3)
MONTHS_BETWEEN(d1, d2)Difference in monthsMONTHS_BETWEEN(SYSDATE, hire_date)
NEXT_DAY(date, 'DAY')Next occurrence of a dayNEXT_DAY(SYSDATE, 'MONDAY')

๐Ÿ”ค String Functions

FunctionDescriptionExample
UPPER(str)Convert to uppercaseUPPER(full_name)
LOWER(str)Convert to lowercaseLOWER(email)
SUBSTR(str, start, length)Extract substringSUBSTR(full_name, 1, 5)
INSTR(str, search)Find positionINSTR(email, '@')
TRIM(str)Remove spacesTRIM(full_name)
REPLACE(str, old, new)Replace textREPLACE(full_name, 'Mr. ', '')

๐Ÿ”ข Numeric Functions

FunctionDescriptionExample
ROUND(num, n)Round numberROUND(salary, 2)
FLOOR(num)Largest whole number ≤ numFLOOR(salary)
CEIL(num)Smallest whole number ≥ numCEIL(salary)
MOD(a, b)RemainderMOD(10, 3) → 1

๐Ÿšซ NULL Functions

FunctionDescriptionExample
NVL(expr1, expr2)Replace NULLNVL(email, 'Not Provided')
COALESCE(expr1, expr2, ...)First non-nullCOALESCE(work_email, personal_email)
NVL2(expr1, expr2, expr3)If not null → expr2, else → expr3NVL2(email, 'Available', 'Missing')

๐Ÿ”น Fusion HCM Real-Time Examples

✅ Example 1: Format Employee Name


SELECT Upper(full_name) AS formatted_name
FROM   per_all_people_f; 

✅ Example 2: Age Calculation

SELECT person_number,
       Trunc(Months_between(sysdate, date_of_birth) / 12) AS age
FROM   per_all_people_f
WHERE  Trunc(sysdate) BETWEEN effective_start_date AND effective_end_date; 

✅ Example 3: Joining Name with Title

SELECT 'Mr. '
       || full_name AS titled_name
FROM   per_all_people_f; 

✅ Example 4: Handle Null Email Addresses


SELECT person_number,
       Nvl(email_address, 'Not Provided') AS contact_email
FROM   per_all_people_f; 

๐Ÿ”น Real-Time Scenario (BI Publisher Use Case)

๐Ÿงพ Scenario:

“Create a report to list active employees with their names in uppercase and show their email addresses, replacing NULLs with 'No Email'.”

✅ SQL Query:


SELECT Upper(full_name)               AS employee_name,
       Nvl(email_address, 'No Email') AS contact_email
FROM   per_all_people_f
WHERE  Trunc(sysdate) BETWEEN effective_start_date AND effective_end_date; 

๐Ÿ”น Practice Exercise

๐Ÿ’ก Task: Write a query to calculate the number of full years an employee has completed since their hire date.

SELECT person_number,
       Trunc(Months_between(sysdate, hire_date) / 12) AS years_completed
FROM   per_all_assignments_m

WHERE  Trunc(sysdate) BETWEEN effective_start_date AND effective_end_date; 

๐Ÿ”น Best Practices

  • Always TRUNC(SYSDATE) when comparing with effective_start_date.

  • Use NVL or COALESCE to prevent nulls from causing display/reporting issues.

  • Avoid applying functions directly on indexed columns in WHERE clauses (can hurt performance).

  • Combine functions to build intelligent logic in reports and fast formulas.


๐Ÿ”น Summary

SQL functions allow you to format, calculate, and clean up data dynamically.
✅ Use date, string, numeric, and null functions frequently in HCM reporting.
✅ Real-time use includes age calculation, null handling, and formatting values.
✅ In BI Publisher and HDL scenarios, functions help deliver meaningful outputs.


๐Ÿ”น Next Steps


Tags: #SQLFunctions, #FusionHCM, #DateLogic, #NullHandling, #BIReports, #OracleSQL

No comments:

Post a Comment