Functions Used in Oracle HRMS Fast Formula
Functions Used in Oracle HRMS Fast Formula
In previous article of Fast Formula, we understood the concept, its usage and different types of
Fast Formulas in Oracle HRMS. In this article i am going to explain the functions that we can
use in Fast formula to make the desired logic. Following are different types of functions that can
be used in the formula
Text Functions
Date Functions
Data Conversion Functions
Number Functions
Functions to Get values from Tables
External Formula Function
Functions Used in Fast Formula
Text Functions
CHR
CHR(n)
The CHR function returns the character having the binary equivalent to number operand n in the
database character set.
Example
/* CHR (10) used to add a newline to the end of REPORT_TEXT2. */
REPORT_TEXT2 = ‘Warning the Transaction Limit has been exceeded’
DEBUG(expr)
This function accepts a string and uses a DBMS_OUTPUT statement to output the string to the
console. Use this function when you are testing a new formula to track its
processing and identify where it is failing.
INITCAP(expr)
The INITCAP function returns the expression expr with the first letter of each word in
uppercase, all other letters in lowercase. Words are delimited by white space or
characters that are not alphanumeric.Back to Top
INSTR(expr1,expr2[,n[,m]])
The INSTR searches expr1 beginning with its nth character for the nth occurrence of expr2 and
returns the position of the character in expr1 that is the first character of this occurrence. If n is
negative, Oracle FastFormula counts and searches backward from the end of expr1. The value
of m must be positive. The default values of both n and m are 1, meaning Oracle FastFormula
begins searching at the first character of expr1 for the first occurrence of expr2. The return value
is relative to the beginning of expr1, regardless of the value of n, and is expressed in characters.
If the search is unsuccessful (if expr2 does not appear m times after the nth character of expr1)
the return value is 0.
INSTRB(expr1,expr2[,n[,m]])
The same as INSTR, except that n and the return value are expressed in bytes, rather than in
characters. For a single-byte database character set, INSTRB is equivalent to INSTR.
LENGTH(expr)
The LENGTH function returns the number of characters in the text string operand expr. Note:
The data type of the result of this function is numeric.
LENGTHB(char)
The LENGTHB function returns the length of char in characters. If char has datatype CHAR, the
length includes all trailing blanks. If char is null, this function returns null.
LOWER(expr)
The LOWER function returns the string operand expr with all letters lowercase. The return value
has the same datatype as the argument expr.
LPAD(expr, n [,pad])
The LPAD function returns the text string operand expr left-padded to length n with the
sequence of characters in pad. The default for pad is a blank. If expr is longer than n, then
LPADreturns the portion of expr that fits in n.
Examples:
/* A is set to ‘XYXYXhello’ */
A = LPAD (‘hello, 10, ‘XY’)
/* A is set to ‘hell’ */
A = LPAD (‘hello’, 4 )
LTRIM(expr [,set])
The LTRIM function returns the text string operand expr with all the leftmost characters that
appear in set removed. The default for set is a blank. If none of the leftmost characters of expr
appear in set then expr is returned
Examples:
/* A is set to ‘def’ */
A = LTRIM (‘abcdef’,’abc’)
/* A is set to ‘abcdef’ */
A = LTRIM (‘abcdef’,’bc’)
RPAD(expr, n [,pad])
The RPAD function returns the text string operand expr right-padded to length n with the
sequence of characters in pad. The default for pad is a blank. If expr is longer than n, then
RPADreturns the portion of expr that fits in n.
Examples:
/* A is set to ‘helloXYXYX’ */
A = RPAD (‘hello, 10, ‘XY’)
/* A is set to ‘hell’ */
A = RPAD (‘hello’, 4 )
RTRIM(expr [,set])
The RTRIM function returns the text string operand expr with all the rightmost characters that
appear in set removed. The default for set is a blank. If none of the
rightmost characters of expr appear in set then expr is returned
Examples:
/* A is set to ‘abc’ */
A = RTRIM (‘abcdef’,’def’)
/* A is set to ‘abcdef’ */
A = RTRIM (‘abcdef’,’de’)
SUBSTR(expr, m [,n])
SUBSTRING(expr, m [,n])
The SUBSTRING function returns a substring of the text string operand expr of length n
characters beginning at the mth character. If you omit the third operand, the substring starts
from m and finishes at the end of expr.
Note: The first operand is a text operand. The second and third operands are numeric
operands. The resulting data type of this function is text.
Tip: Always check string length before you start to substring.
For example:
/* Check that the tax code starts with GG */
IF length(Tax_code) <= 2
THEN
(message = ‘Tax code is too short’
RETURN message
)
IF substr( Tax_code, 1, 2) = ‘GG’ THEN …
Or, to check if Tax_code is a string of at least two characters starting
with ‘GG’:
IF Tax_code LIKE ‘GG%’ THEN …
SUBSTRB(expr, m [,n])
The same as SUBSTR, except that the arguments m and n are expressed in bytes, rather than
in characters. For a single-byte database character set, SUBSTRB is equivalent to SUBSTR.
UPPER(expr)
The UPPER function converts a text string to upper case.
Numeric Functions
ABS(n)
The ABS function returns the magnitude of a numeric operand n as a positive numeric value. If
the value of the operand is positive, its value returns unchanged. If the operand is negative then
the value’s sign inverts, and the value returns as a positive number.
Example:
ABS (-17) returns 17
FLOOR(n)
The FLOOR function returns the integer part of a numeric operand n. If the value of the operand
contains information after the decimal point, Oracle
FastFormula discards that information and returns a whole number.
Example:
FLOOR(35.455) returns 35
GREATEST(n, n [, n] . . .)
GREATEST_OF(n, n [, n] . . .)
The GREATEST function compares all the operands and returns the largest value.
LEAST(n, n [, n] . . .)
LEAST_OF(n, n [, n] . . .)
The LEAST function compares all the operands and returns the smallest value.
POWER(m,n)
Returns m raised to the nth power. The base m and the exponent n can be any numbers, but if
m is negative, n must be an integer.
ROUND(n [, m])
The ROUND function rounds off a numeric value n to m decimal places and a date depending
on the format of m. For numeric values, the first operand is the value Oracle FastFormula
rounds off, the second the number of places Oracle FastFormula rounds off to. For dates,
ROUND returns n rounded to the unit specified by the format model of m such as Year or Day.
Refer to the SQL Language Reference Manual for details of the
valid formats you can specify.
Examples:
ROUND(2.3401, 2) returns 2.34
ROUND (2.3461, 2) returns 2.35
ROUND (TO_DATE(’27-OCT-1992′, ‘DD-MON-YYYY’), ‘YEAR’) returns 01-JAN-1993
ROUNDUP(n [, m])
ROUND_UP(n [, m])
The ROUNDUP function rounds a numeric value n up to m decimal places. The first operand is
the value to be rounded up, the second the number of places to round to. If the digits after the
rounding point are zero, the value is unchanged. If the digits are not zero, the value is
incremented at the rounding point.
Examples:
ROUND_UP(2.3401, 2) returns 2.35
ROUND_UP(2.3400, 2) returns 2.34.
TRUNC(n [, m])
TRUNCATE(n [, m])
The TRUNC function rounds a numeric value n down to m decimal places. The first operand is
the value to be rounded down, the second the number of places to round to. TRUNC also
returns n with the time portion of the day truncated to the unit specified by the format model of
m. If you omit m, d is truncated to the nearest day The default model, ‘DD’, returns the date
rounded or truncated to the day with a time of midnight. Oracle FastFormula drops all digits (if
any) after the specified truncation point.
Examples:
TRUNC(2.3401, 2) returns 2.34.
TRUNC(TO_DATE(’27-OCT-1992′, ‘DD-MON-YYYY’), ‘YEAR’) returns 01-JAN-1992
Date Functions
ADD_DAYS(date, n)
The ADD_DAYS function adds a number of days to a date. The resulting date accords with the
calendar. Note: Oracle FastFormula ignores any fractional part of the number n.
Example:
ADD_DAYS (’30-DEC-1990′ (date), 6) returns 5 JAN 1991
ADD_MONTHS(date, n)
The ADD_MONTHS function adds a number of months to a date. The resulting date accords
with the calendar. Note: Oracle FastFormula ignores any fractional part of the number n.
ADD_YEARS(date, n)
The ADD_YEARS function adds a number of years to a date. The resulting date accords with
the calendar. Note: Oracle FastFormula ignores any fractional part of the number n.
LAST_DAY(d)
The LAST_DAY function returns the date of the last day of the month that contains d. You might
use this function to determine how many days are left in the current month.
DAYS_BETWEEN(date1, date2)
The DAYS_BETWEEN function returns the number of days between two dates. If the later date
is first, the result is a positive number. If the earlier date is first, the result is a negative number.
The number returned is also based on the real calendar.
Note: The result is a numeric data type.
Example:
DAYS_BETWEEN(‘1995/06/27 00:00:00’ (date), ‘1995/07/03 00:00:00’ (date)) returns -5
MONTHS_BETWEEN(date1, date2)
The MONTHS_BETWEEN function returns the number of months between two dates. If the
later date is first, the result is a positive number. If the earlier date is first, the result is a negative
number. The number returned is also based on the real calendar. If the result is not a whole
number of months (that is, there are some days as well), the days part is shown as a decimal.
Note: The result is a numeric data type.
INSTR(expr1,expr2[,n[,m]])
The INSTR function searches expr1 beginning with its nth character for the mth occurrence of
expr2 and returns the position of the character in expr1 that is the first
character of this occurrence. If n is negative, Oracle FastFormula counts and searches
backwards.
NUM_TO_CHAR(n, format)
Converts the number n from number data type to text data type using the specified format. This
function is equivalent to the SQL TO_CHAR function. For example:
NUM_TO_CHAR(amount, ‘$9,990.99’) This returns the amount with a leading dollar sign,
commas every three digits, and two decimal places. Refer to the SQL Language Reference
Manual for a full list of the valid number formats you can specify.
Note: When assigning date variables from constants it is much more efficient to say:
GET_LOOKUP_MEANING(lookup_type , lookup_code)
The GET_LOOKUP_MEANING function enables Oracle FastFormula to translate a lookup code
into a meaning. This can be used for any descriptive flexfield items or
developer flexfield items that are based on lookups.
Example:
GET_LOOKUP_MEANING (‘ETH_TYPE’, PEOPLE_GB_ETHNIC_ORIGIN)
RATES_HISTORY(element or rate type name, date, element or rate type indicator, time
dimension)
This function uses information stored in the UK Element Attribution Information EIT and
information about the assignment’s contract type to calculate a payment rate as of the given
date and expressed for the selected time dimension (such as hourly or annual). If the element or
rate type indicator is R, the function sums the rates for all elements classified with the given rate
type (which is stored against the element in the Rate Type Information EIT).
The time dimension parameter must be A (annual), D (daily), H (hourly), or P (periodic). The
element or rate type parameter must be R (rate type) or E (element).
The function can also adjust the returned rate for FTE and length of service, if these factors are
set to Yes in the Element Attribution Information.Back to Top
External Formula Function
External Functions refers to logic written in database package and calling in fast formula by
defining it through Define Function in Oracle HRMS. I shall write a seperate article on it.