BI Publisher has extended a set of SQL and XSL functions for use in RTF templates.
The syntax for these extended functions is
<?xdofx:expression?>
for extended SQL functions or
<?xdoxslt:expression?>
for extended XSL functions.
You cannot mix xdofx
statements with XSL expressions in the same context. For example, assume that you had two elements, FIRST_NAME and LAST_NAME to concatenate into a 30-character field and right pad the field with the character "x". You could not use the following:
Incorrect:
<?xdofx:rpad(concat(FIRST_NAME,LAST_NAME),30, 'x')?>
because concat is an XSL expression. Instead, you could use the following:
Correct:
<?xdofx:rpad(FIRST_NAME||LAST_NAME),30,'x')?>
The supported functions are shown in the following table:
SQL Statement or XSL Expression | Usage | Description |
---|---|---|
2+3 |
|
Addition |
2-3 |
|
Subtraction |
2*3 |
|
Multiplication |
2 div 3 |
|
Division |
2**3 |
|
Exponential |
3||2 |
|
Concatenation |
sdiv() |
|
Safe divide function returns a specified value if the result of the function is not a number (NaN). In the syntax shown, num1 is the dividend; num2 is the divisor and string is the value to be returned if NaN is returned. Examples:
|
lpad('aaa',10,'.') |
|
The lpad function pads the left side of a string with a specific set of characters. The syntax for the lpad function is: lpad(string1,padded_length,[pad_string])string1 is the string to pad characters to (the left-hand side).padded_length is the number of characters to return.pad_string is the string that is padded to the left-hand side of string1 . |
rpad('aaa',10,'.') |
|
The rpad function pads the right side of a string with a specific set of characters. The syntax for the rpad function is: rpad(string1,padded_length,[pad_string]).string1 is the string to pad characters to (the right-hand side).padded_length is the number of characters to return.pad_string is the string that is padded to the right-hand side of string1 |
trim() |
|
Removes spaces in a string. Enter the text to be trimmed, the function returns the trimmed text. |
ltrim() |
|
Removes the leading white spaces in a string. |
rtrim() |
|
Removes the trailing white spaces in a string. |
truncate |
|
The truncate function returns number truncated to integer places right of the decimal point. If integer is omitted, then number is truncated to the whole integer value. integer can be negative to truncate values left of the decimal point. integer must be an integer. Example: |
replicate |
|
The replicate function replicates the specified string the specified number of times. Example: |
decode('xxx','bbb','ccc','xxx','ddd') |
|
The decode function has the functionality of an IF-THEN-ELSE statement. The syntax for the decode function is: decode(expression, search, result [,search, result]...[, default])expression is the value to compare.search is the value that is compared against expression.result is the value returned, if expression is equal to search.default is returned if no matches are found. |
Instr('abcabcabc','a',2) |
<?xdofx:Instr('abcabcabc','a',2)?> |
The instr function returns the location of a substring in a string. The syntax for the instr function is: instr(string1,string2,[start_position],[nth_appearance])string1 is the string to search.string2 is the substring to search for in string1.start_position is the position in string1 where the search starts. The first position in the string is 1. If the start_position is negative, the function counts back start_position number of characters from the end of string1 and then searches towards the beginning of string1.nth appearance is the nth appearance of string2. |
substr('abcdefg',2,3) |
|
The substr function allows you to extract a substring from a string. The syntax for the substr function is: substr(string, start_position, length)string is the source string.start_position is the position for extraction. The first position in the string is always 1.length is the number of characters to extract. |
left |
|
Enables you to extract the specified number of characters from a string, starting from the left. The syntax is left(string, Numchars) For example, |
right |
|
Enables you to extract the specified number of characters from a string, starting from the right. The syntax is right(string, Numchars) For example, |
replace(name,'John','Jon') |
|
The replace function replaces a sequence of characters in a string with another set of characters. The syntax for the replace function is: replace(string1,string_to_replace,[replacement_string])string1 is the string to replace a sequence of characters with another set of characters.string_to_replace is the string that is searched for in string1.replacement_string is optional. All occurrences of string_to_replace are replaced with replacement_string in string1. |
to_number('12345') |
|
Function to_number converts char, a value of CHAR, VARCHAR2, NCHAR, or NVARCHAR2 datatype that contains a number in the format that is specified by the optional format model fmt, to a value of NUMBER datatype. |
format_number |
|
Converts a number to a string and formats the number according to the locale specified in $_XDOLOCALE and to the number of decimal positions specified in n using Java's default symbols. For example: |
format_number |
|
Converts a number to a string and uses the specified separators: s1 for the thousand separator and s2 for the decimal separator. For example: |
pat_format_number |
|
Returns a number formatted with the specified pattern. For example: |
to_char(12345) |
|
Use the TO_CHAR function to translate a value of NUMBER datatype to VARCHAR2 datatype. |
to_date |
<?xdofx:to_date ( char [, fmt [, 'nlsparam']] ) |
TO_DATE converts char of CHAR, VARCHAR2, NCHAR, or NVARCHAR2 datatype to a value of DATE datatype. The fmt is a date format specifying the format of char. If you omit fmt, then char must be in the default date format. If fmt is 'J', for Julian, then char must be an integer. |
format_date() |
|
Reads date in one format and creates in another format. |
sysdate() |
|
SYSDATE returns the current date and time in XML canonical date format (for example: 1997-07-16T19:20:30.45+01:00). The datatype of the returned value is DATE. The function requires no arguments. See Displaying the System Date (sysdate) in Reports for information on properly formatting the sysdate in report output. |
current_date() |
|
Returns the current date in yyyy-MM-dd format in the given locale and timezone. This function supports only the Gregorian calendar. |
current_time() |
|
Returns the current time in the given locale and timezone. This function supports only the Gregorian calendar. |
minimum |
|
Returns the minimum value of the element in the set. |
date_diff |
|
This function provides a method to get the difference between two dates in the given locale. The dates must be in "yyyy-MM-dd" format. This function supports only the Gregorian calendar. The syntax is as follows:
Example: returns 1 Example: returns -14 Example: returns -7 |
sec_diff |
|
This function provides a method to get the difference between two dates in seconds in the given locale. The dates must be in "yyyy-MM-dd'T'HH:mm:ss". This function supports only Gregorian calendar. Example: |
get_day |
|
This function provides a method to get the day value of a date in yyyy-MM-dd format in the given locale. This function supports only the Gregorian calendar. Example: |
get_month |
|
This function provides a method to get the month value of a date in yyyy-MM-dd format in the given locale. This function supports only the Gregorian calendar. Example: |
get_year |
|
This function provides a method to get the year value of a date in yyyy-MM-dd format in the given locale. This function supports only the Gregorian calendar. Example: |
month_name |
|
This function provides a method to get the name of the month in the given locale. This function supports only the Gregorian calendar. The syntax for this function is: |
maximum |
|
Returns the maximum value of the element in the set. |
abs |
|
Returns the absolute value of the number entered. Example: |
chr |
|
CHR returns the character having the binary equivalent to n in either the database character set or the national character set. |
ceil |
|
CEIL returns smallest integer greater than or equal to n. |
floor |
|
FLOOR returns largest integer equal to or less than n. |
round (SQL function) |
|
ROUND returns number rounded to integer places right of the decimal point. If integer is omitted, then number is rounded to 0 places. integer can be negative to round off digits left of the decimal point. integer must be an integer. Example: |
round (XSLT function) |
|
ROUND returns number rounded to integer places right of the decimal point. If integer is omitted, then number is rounded to 0 places. integer can be negative to round off digits left of the decimal point. integer must be an integer. Example: |
lower |
|
LOWER returns char, with all letters lowercase. char can be any of the datatypes CHAR, VARCHAR2, NCHAR, NVARCHAR2, CLOB, or NCLOB. The return value is the same datatype as char. |
upper |
|
UPPER returns char, with all letters uppercase. char can be any of the datatypes CHAR, VARCHAR2, NCHAR, NVARCHAR2, CLOB, or NCLOB. The return value is the same datatype as char. |
length |
|
The "length" function returns the length of char. LENGTH calculates length using characters as defined by the input character set. |
greatest |
|
GREATEST returns the greatest of the list of exprs. All exprs after the first are implicitly converted to the datatype of the first expr before the comparison. |
least |
|
LEAST returns the least of the list of exprs. All exprs after the first are implicitly converted to the datatype of the first expr before the comparison. |
next_element |
|
Method to get the next element in the current group. Returns the element that occurs after the element named. For example: |
prev_element |
|
Method to get the previous element in the current group. Returns the element that occurs before the element named. For example: |
set_array |
|
Sets a value in a hash table. Syntax is |
get_array |
|
Returns the value at the specified index of the hash table. Syntax is |
The following table shows supported combination functions.
SQL Statement | Usage |
---|---|
(2+3/4-6*7)/8 |
|
lpad(substr('1234567890',5,3),10,'^') |
|
decode('a','b','c','d','e','1')||instr('321',1,1) |
|
This function enables the conversion of numbers to words for RTF template output.
This is a common requirement for check printing.
The new function is "to_check_number". The syntax of this function is
<?xdofx:to_check_number(amount, precisionOrCurrency, caseType, decimalStyle)?>
The following table describes the function attributes.
Attribute | Description | Valid Value |
---|---|---|
amount |
The number to be transformed. |
Any number |
precisionOrCurrency |
For this attribute you can specify either the precision, which is the number of digits after the decimal point; or the currency code, which governs the number of digits after the decimal point. The currency code does not generate a currency symbol in the output. |
An integer, such as 2; or a currency code, such as 'USD'. |
caseType |
The case type of the output. |
Valid values are: 'CASE_UPPER', 'CASE_LOWER', 'CASE_INIT_CAP' |
decimalStyle |
Output type of the decimal fraction area. |
Valid values are: 'DECIMAL_STYLE_FRACTION1', 'DECIMAL_STYLE_FRACTION2', 'DECIMAL_STYLE_WORD' |
The following table displays the example function as entered in an RTF template and the returned output.
RTF Template Entry | Returned Output |
---|---|
<?xdofx:to_check_number(12345.67, 2)?> |
Twelve thousand three hundred forty-five and 67/100 |
<?xdofx:to_check_number(12345.67, 'USD')?> |
Twelve thousand three hundred forty-five and 67/100 |
<?xdofx:to_check_number(12345, 'JPY', 'CASE_UPPER')?> |
TWELVE THOUSAND THREE HUNDRED FORTY-FIVE |
<?xdofx:to_check_number(12345.67, 'EUR', 'CASE_LOWER', 'DECIMAL_STYLE_WORDS')?> |
twelve thousand three hundred forty-five and sixty-seven |
XSL time logging commands are added to the XSL template to enable time measurements, which acts as a profiling tool. When the template is run, a log.csv file is generated which measures the time across the XSL code.