✅ 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
Function | Description | Example |
---|---|---|
SYSDATE | Current date | SYSDATE |
TRUNC(date) | Remove time | TRUNC(SYSDATE) |
ADD_MONTHS(date, n) | Add months | ADD_MONTHS(hire_date, 3) |
MONTHS_BETWEEN(d1, d2) | Difference in months | MONTHS_BETWEEN(SYSDATE, hire_date) |
NEXT_DAY(date, 'DAY') | Next occurrence of a day | NEXT_DAY(SYSDATE, 'MONDAY') |
๐ค String Functions
Function | Description | Example |
---|---|---|
UPPER(str) | Convert to uppercase | UPPER(full_name) |
LOWER(str) | Convert to lowercase | LOWER(email) |
SUBSTR(str, start, length) | Extract substring | SUBSTR(full_name, 1, 5) |
INSTR(str, search) | Find position | INSTR(email, '@') |
TRIM(str) | Remove spaces | TRIM(full_name) |
REPLACE(str, old, new) | Replace text | REPLACE(full_name, 'Mr. ', '') |
๐ข Numeric Functions
Function | Description | Example |
---|---|---|
ROUND(num, n) | Round number | ROUND(salary, 2) |
FLOOR(num) | Largest whole number ≤ num | FLOOR(salary) |
CEIL(num) | Smallest whole number ≥ num | CEIL(salary) |
MOD(a, b) | Remainder | MOD(10, 3) → 1 |
๐ซ NULL Functions
Function | Description | Example |
---|---|---|
NVL(expr1, expr2) | Replace NULL | NVL(email, 'Not Provided') |
COALESCE(expr1, expr2, ...) | First non-null | COALESCE(work_email, personal_email) |
NVL2(expr1, expr2, expr3) | If not null → expr2, else → expr3 | NVL2(email, 'Available', 'Missing') |
๐น Fusion HCM Real-Time Examples
✅ Example 1: Format Employee Name
✅ Example 2: Age Calculation
✅ Example 3: Joining Name with Title
✅ Example 4: Handle Null Email Addresses
๐น 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:
๐น 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 witheffective_start_date
. -
Use
NVL
orCOALESCE
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
-
Previous Chapter: Mastering SQL for Oracle Fusion HCM – Chapter 6 : SQL ORDER BY and Sorting Logic in Fusion HCM
Next Chapter: Mastering SQL for Oracle Fusion HCM –Chapter 8. Handling NULLs in SQL for Fusion HCM
Tags: #SQLFunctions
, #FusionHCM
, #DateLogic
, #NullHandling
, #BIReports
, #OracleSQL
No comments:
Post a Comment