Common Expression Editor Functions in Informatica Analyst
Common Expression Editor Functions in Informatica Analyst
Informatica Analyst
© 2011 Informatica
Abstract
You can use functions in the Expression Editor in Informatica Analyst (the Analyst tool) to add expression functions to rules
and filters in a mapping specification. This article describes the common functions that data integration analysts use in the
Expression Editor.
Supported Versions
¨ Informatica Data Services 9.1.0
¨ PowerCenter 9.1.0
Table of Contents
Expression Editor Overview. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
Expression Functions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
CONCAT. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
DECODE. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
INITCAP. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
INSTR. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
ISNULL. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
IS_NUMBER. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
LOWER. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
UPPER. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
LPAD. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
RPAD. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
LTRIM. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
RTRIM. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
REPLACECHR. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
REPLACESTR. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
ROUND (Numbers). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
SUBSTR. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
TO_CHAR (Dates). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
TO_DATE. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
TRUNC (Numbers). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
Use the Expression Editor to select functions, configure columns as inputs to the functions, validate the expression, and
configure the return type, precision, and scale.
For example, when you add an advanced filter to a mapping specification, the Expression Editor appears on the Add Filter
window.
2
The following figure describes an advanced filter that uses the Expression Editor to add the ISNULL function to a customer
address column.
For example, when you create a rule for a target column in a mapping specification, the Expression Editor appears on the
Add Rule window.
3
The following figure describes a rule that uses the Expression Editor to add the INITCAP function to capitalize first names.
Expressions modify data or test whether data matches conditions. You can create a simple expression that only contains a
column, such as ORDERS, or a numeric literal, such as 10. You can also write complex expressions that include functions
nested within functions.
This article describes the common expression functions that data integration analysts use. Each function description includes:
¨ Syntax
¨ Return value
¨ Example
Expression Functions
The Expression Editor provides different types of functions such as aggregate, character, or numerical functions to use in
expressions. You can also use the Expression Editor to create your own expressions.
Data integration analysts can use the following common functions to build mapping specification logic:
¨ CONCAT
¨ DECODE
¨ INITCAP
¨ INSTR
¨ ISNULL
4
¨ IS_NUMBER
¨ LOWER
¨ UPPER
¨ LPAD
¨ RPAD
¨ LTRIM
¨ RTRIM
¨ REPLACECHR
¨ REPLACESTR
¨ ROUND
¨ SUBSTR
¨ TO_CHAR
¨ TO_DATE
¨ TRUNC
CONCAT
Concatenates two strings. CONCAT converts all data to text before concatenating the strings.
Syntax
CONCAT( first_string, second_string )
first_string Required Any datatype except Binary. The first part of the string you want to concatenate. You can
enter any valid transformation expression.
second_string Required Any datatype except Binary. The second part of the string you want to concatenate. You
can enter any valid transformation expression.
Return Value
String.
Nulls
If one of the strings is NULL, CONCAT ignores it and returns the other string.
Example
The following expression concatenates the names in the FIRST_NAME and LAST_NAME columns in an
ALL_CUSTOMERS table:
CONCAT( ALL_CUSTOMERS.FIRST_NAME, ALL_CUSTOMERS.LAST_NAME )
5
FIRST NAME LAST NAME RETURN VALUE
The following figure shows the CONCAT function in the Expression Editor that concatenates the names in the
FiIRST_NAME and LAST_NAME columns in an ALL_CUSTOMERS table:
6
CONCAT does not add spaces to separate strings. If you want to add a space between two strings, you can write an
expression with two nested CONCAT functions. For example, the following expression first concatenates a space on the end
of the first name and then concatenates the last name:
CONCAT( CONCAT( ALL_CUSTOMERS.FIRST_NAME, ' ' ), ALL_CUSTOMERS.LAST_NAME )
DECODE
Searches a column for a value you specify. If the function finds the value, it returns a result value, which you define. You can
build an unlimited number of searches within a DECODE function.
If you use DECODE to search for a value in a string column, you can either trim trailing blanks with the RTRIM function or
include the blanks in the search string.
Syntax
DECODE( value, first_search, first_result [, second_search, second_result]...[,default] )
value Required Any datatype except Binary. Passes the values you want to search.
search Required Any value with the same datatype as the value argument. Passes the values for which you
want to search. The search value must match the value argument. You cannot search for a
portion of a value. Also, the search value is case sensitive.
For example, if you want to search for the string 'Halogen Flashlight' in a particular column,
you must enter 'Halogen Flashlight, not just 'Halogen'. If you enter 'Halogen', the search does
not find a matching value.
result Required Any datatype except Binary. The value you want to return if the search finds a matching value.
default Optional Any datatype except Binary. The value you want to return if the search does not find a
matching value.
Return Value
First_result if the search finds a matching value.
NULL if you omit the default argument and the search does not find a matching value.
Examples
You might use DECODE in an expression that searches for a particular ITEM_ID and returns the ITEM_NAME in an
ALL_CUSTOMERS table:
DECODE( ALL_CUSTOMERS.ITEM_ID, 10, 'Flashlight',
14, 'Regulator',
20, 'Knife',
7
40, 'Tank',
'NONE' )
DECODE returns the default value of NONE for items 17 and 25 because the search values did not match the ITEM_ID.
Also, DECODE returns NONE for the NULL ITEM_ID.
The following figure shows the DECODE function in the Expression Editor that searches for a particular ITEM_ID and
returns the ITEM_NAME in an ALL_CUSTOMERS table:
The following expression tests multiple columns and conditions, evaluated in a top to bottom order for TRUE or FALSE in an
ALL_CUSTOMERS table:
DECODE( TRUE,
ALL_CUSTOMERS.VAR1 = 22, 'Variable 1 was 22!',
ALL_CUSTOMERS.VAR2 = 49, 'Variable 2 was 49!',
ALL_CUSTOMERS.VAR1 < 23, 'Variable 1 was less than 23.',
8
ALL_CUSTOMERS.VAR2 > 30, 'Variable 2 was more than 30.',
'Variables were out of desired ranges.')
INITCAP
Capitalizes the first letter in each word of a string and converts all other letters to lowercase. Words are delimited by white
space (a blank space, formfeed, newline, carriage return, tab, or vertical tab) and characters that are not alphanumeric. For
example, if you pass the string ‘…THOMAS’, the function returns Thomas.
Syntax
INITCAP( string )
string Required Any datatype except Binary. You can enter any valid transformation expression.
Return Value
String.
Example
The following expression capitalizes all names in the FIRST_NAME column in an ALL_CUSTOMERS table:
INITCAP( ALL_CUSTOMERS.FIRST_NAME )
9
The following figure shows the INITCAP function in the Expression Editor that capitalizes all names in the FIRST_NAME
column in an ALL_CUSTOMERS table:
INSTR
Returns the position of a character set in a string, counting from left to right.
Syntax
INSTR( string, search_value [,start [,occurrence [,comparison_type ]]] )
string Required The string must be a character string. Passes the value you want to evaluate. The results of
the expression must be a character string. If not, INSTR converts the value to a string before
evaluating it.
search_value Required Any value. The search value is case sensitive. The set of characters you want to search for.
The search_value must match a part of the string. For example, if you write INSTR('Alfred
Pope', 'Alfred Smith') the function returns 0.
If you want to search for a character string, enclose the characters you want to search for in
single quotation marks, for example 'abc'.
start Optional Must be an integer value. The position in the string where you want to start the search.
10
Argument Required/ Description
Optional
The default is 1, meaning that INSTR starts the search at the first character in the string.
If the start position is 0, INSTR searches from the first character in the string. If the start
position is a positive number, INSTR locates the start position by counting from the beginning
of the string. If the start position is a negative number, INSTR locates the start position by
counting from the end of the string. If you omit this argument, the function uses the default
value of 1.
occurrence Optional A positive integer greater than 0. If the search value appears more than once in the string,
you can specify which occurrence you want to search for. For example, you would enter 2 to
search for the second occurrence from the start position.
If you omit this argument, the function uses the default value of 1, meaning that INSTR
searches for the first occurrence of the search value. If you pass a decimal, the function uses
the value rounded to the nearest integer value. If you pass a negative integer or 0, the
expression is not valid.
comparison_type Optional The string comparison type, either linguistic or binary, when the Data Integration Service runs
in Unicode mode. When the Data Integration Service runs in ASCII mode, the comparison
type is always binary.
Linguistic comparisons take language-specific collation rules into account, while binary
comparisons perform bitwise matching. For example, the German sharp s character matches
the string “ss” in a linguistic comparison, but not in a binary comparison. Binary comparisons
run faster than linguistic comparisons.
Must be an integer value, either 0 or 1:
- 0: INSTR performs a linguistic string comparison.
- 1: INSTR performs a binary string comparison.
Default is 0.
Return Value
Integer if the search is successful. Integer represents the position of the first character in the search_value, counting from
left to right.
Examples
The following expression returns the position of the first occurrence of the letter ‘a’, starting at the beginning of each
company name. Because the search_value argument is case sensitive, it skips the ‘A’ in ‘Blue Fin Aqua Center’, and returns
the position for the ‘a’ in ‘Aqua’:
INSTR( ALL_CUSTOMERS.COMPANY, 'a' )
11
The following figure shows the INSTR function in the Expression Editor that returns the position of the first occurence of the
letter 'a', starting at the begining of company name in the ALL_CUSTOMERS table:
The following expression returns the position of the second occurrence of the letter ‘a’, starting at the beginning of each
company name. Because the search_value argument is case sensitive, it skips the ‘A’ in ‘Blue Fin Aqua Center’, and returns
0:
INSTR( ALL_CUSTOMERS.COMPANY, 'a', 1, 2 )
The following expression returns the position of the second occurrence of the letter ‘a’ in each company name, starting from
the last character in the company name. Because the search_value argument is case sensitive, it skips the ‘A’ in 'Blue Fin
Aqua Center’, and returns 0:
INSTR( ALL_CUSTOMERS.COMPANY, 'a', -1, 2 )
12
COMPANY RETURN VALUE
Frank's Dive Shop 0
VIP Diving Club 0
The following expression returns the position of the first character in the string ‘Blue Fin Aqua Center’ (starting from the last
character in the company name):
INSTR( ALL_CUSTOMERS.COMPANY, 'Blue Fin Aqua Center', -1, 1 )
The following expression evaluates a string, starting from the end of the string. The expression finds the last (rightmost)
space in the string and then returns all characters to the left of it:
SUBSTR( ALL_CUSTOMERS.CUST_NAME,1,INSTR( ALL_CUSTOMERS.CUST_NAME,' ' ,-1,1 ))
ISNULL
Returns whether a value is NULL. ISNULL evaluates an empty string as FALSE.
Syntax
ISNULL( value )
value Required Any datatype except Binary. Passes the rows you want to evaluate.
Return Value
TRUE (1) if the value is NULL.
13
Example
The following example checks for null values in an ITEM_NAME column in an ALL_CUSTOMERS table:
ISNULL( ALL_CUSTOMERS.ITEM_NAME )
The following figure shows the ISNULL function in the Expression Editor that checks for null values in an ITEM_NAME
column in an ALL_CUSTOMERS table:
IS_NUMBER
Returns whether a string is a valid number.
14
¨ Optional scientific notation, such as the letter ‘e’ or ‘E’ (and the letter ‘d’ or ‘D’ on Windows) followed by an optional
sign (+/-), followed by one or more digits
¨ Optional white space following the number
The output column for an IS_NUMBER expression must be a String or Numeric datatype.
You can use IS_NUMBER to test or filter data in a flat file before writing it to a target.
Syntax
IS_NUMBER( value )
value Required Must be a String datatype. Passes the rows you want to evaluate.
Return Value
TRUE (1) if the row is a valid number.
Examples
The following expression checks for valid numbers in an ITEM_PRICE column in an ALL_CUSTOMERS table:
IS_NUMBER( ALL_CUSTOMERS.ITEM_PRICE )
15
The following figure shows the IS_NUMBER function in the Expression Editor that checks for valid numbers in an
ITEM_PRICE column in an ALL_CUSTOMERS table:
Use IS_NUMBER to test data before using one of the numeric conversion functions, such as TO_FLOAT. For example, the
following expression checks the values in the ITEM_PRICE column and converts each valid number to a double-precision
floating point value. If the value is not a valid number, function return value is 0.00:
IIF( IS_NUMBER ( ALL_CUSTOMERS.ITEM_PRICE ), TO_FLOAT( ALL_CUSTOMERS.ITEM_PRICE ), 0.00 )
16
LOWER
Converts uppercase string characters to lowercase.
Syntax
LOWER( string )
string Required Any string value. The argument passes the string values that you want to return as lowercase.
You can enter any valid expression that evaluates to a string.
Return Value
Lowercase character string. If the data contains multibyte characters, the return value depends on the code page and data
movement mode of the Data Integration Service.
Example
The following expression returns lowercase for all first names in a FIRST_NAME column in an ALL_CUSTOMERS table:
LOWER( ALL_CUSTOMERS.FIRST_NAME )
17
The following figure shows the LOWER function in the Expression Editor that returns lowercase for all first names in a
FIRST_NAME column in an ALL_CUSTOMERS table:
UPPER
Converts lowercase string characters to uppercase.
Syntax
UPPER( string )
string Required String datatype. Passes the values you want to change to uppercase text.
Return Value
Uppercase string. If the data contains multibyte characters, the return value depends on the code page and data movement
mode of the Data Integration Service.
18
Example
The following expression returns uppercase for all first names in a FIRST_NAME column in an ALL_CUSTOMERS table:
UPPER( ALL_CUSTOMERS.FIRST_NAME )
The following figure shows the UPPER function in the Expression Editor that returns uppercase for all first names in a
FIRST_NAME column in an ALL_CUSTOMERS table:
19
LPAD
Adds a set of blanks or characters to the beginning of a string to set the string to a specified length.
Syntax
LPAD( first_string, length [,second_string] )
first_string Required Can be a character string. The strings you want to change.
length Required Must be a positive integer literal. This argument specifies the length you want each string to
be.
second_string Optional Can be any string value. The characters you want to append to the left-side of the
first_string values. You can enter a specific string literal. However, enclose the characters
you want to add to the beginning of the string within single quotation marks, as in 'abc'. This
argument is case sensitive. If you omit the second_string, the function pads the beginning of
the first string with blanks.
Return Value
String of the specified length.
Examples
The following expression standardizes numbers to six digits by padding them with leading zeros.
LPAD( ALL_CUSTOMERS.PART_NUM, 6, '0')
LPAD counts the length from left to right. If the first string is longer than the length, LPAD truncates the string from right to
left. For example, LPAD(‘alphabetical’, 5, ‘x’) returns the string ‘alpha’.
20
The following figure shows the LPAD function in the Expression Editor that standardizes numbers to six digits in a
PART_NUM column in the ALL_CUSTOMERS table:
If the second string is longer than the total characters needed to return the specified length, LPAD uses a portion of the
second string:
LPAD( ALL_CUSTOMERS.ITEM_NAME, 16, '*..*' )
21
RPAD
Converts a string to a specified length by adding blanks or characters to the end of the string.
Syntax
RPAD( first_string, length [,second_string] )
first_string Required Any string value. The strings you want to change.
length Required Must be a positive integer literal. Specifies the length you want each string to be.
second_string Optional Any string value. Passes the string you want to append to the right-side of the first_string
values. Enclose the characters you want to add to the end of the string within single
quotation marks, for example, 'abc'. This argument is case sensitive.
If you omit the second string, the function pads the end of the first string with blanks.
Return Value
String of the specified length.
Examples
The following expression returns the item name with a length of 16 characters, appending the string '.' to the end of each
item name:
RPAD( ALL_CUSTOMERS.ITEM_NAME, 16, '.')
22
The following figure shows the RPAD function in the Expression Editor that returns the item name with a length of 16
characters, appending the string '.' to the end of each item name:
RPAD counts the length from left to right. So, if the first string is longer than the length, RPAD truncates the string from right
to left. For example, RPAD(‘alphabetical’, 5, ‘x’) would return the string ‘alpha’. RPAD uses a partial part of the
second_string when necessary.
The following expression returns the item name with a length of 16 characters, appending the string ‘*..*’ to the end of each
item name:
RPAD( ALL_CUSTOMERS.ITEM_NAME, 16, '*..*' )
LTRIM
Removes blanks or characters from the beginning of a string.
¨ In UNICODE mode, LTRIM removes both single- and double-byte spaces from the beginning of a string.
23
If you use LTRIM to remove characters from a string, LTRIM compares the trim_set to each character in the string
argument, character-by-character, starting with the left side of the string. If the character in the string matches any character
in the trim_set, LTRIM removes it. LTRIM continues comparing and removing characters until it fails to find a matching
character in the trim_set. Then it returns the string, which does not include matching characters.
Syntax
LTRIM( string [, trim_set] )
string Required Any string value. Passes the strings you want to modify. Use operators to perform comparisons
or concatenate strings before removing characters from the beginning of a string.
trim_set Optional Any string value. Passes the characters you want to remove from the beginning of the first
string. You can also enter a character string. However, you must enclose the characters you
want to remove from the beginning of the string within single quotation marks, for example,
'abc'. If you omit the second string, the function removes any blanks from the beginning of the
string.
LTRIM is case sensitive. For example, if you want to remove the 'A' character from the string
'Alfredo', you would enter 'A', not 'a'.
Return Value
String. The string values with the specified characters in the trim_set argument removed.
NULL if a value passed to the function is NULL. If the trim_set is NULL, the function returns NULL.
Example
The following expression removes the characters ‘S’ and ‘.’ from the strings in the LAST_NAME column:
LTRIM( ALL_CUSTOMERS.LAST_NAME, 'S.')
24
The following figure shows the LTRIM function in the Expression Editor that removes the characters 'S' and '.' from the
strings in a LAST_NAME column in an ALL_CUSTOMERS table:
LTRIM removes ‘S.’ from S. MacDonald and the ‘S’ from both Sawyer and Steadman, but not the period from H. Bender.
This is because LTRIM searches, character by character, for the set of characters you specify in the trim_set argument. If
the first character in the string matches the first character in the trim_set, LTRIM removes it. Then LTRIM looks at the
second character in the string. If it matches the second character in the trim_set, LTRIM removes it, and so on. When the
first character in the string does not match the corresponding character in the trim_set, LTRIM returns the string and
evaluates the next row.
In the example of H. Bender, H does not match either character in the trim_set argument, so LTRIM returns the string in the
LAST_NAME column and moves to the next row.
You can also remove multiple sets of characters by nesting LTRIM. For example, if you want to remove leading blanks and
the character 'T' from a column of names, you might create an expression similar to the following:
LTRIM( LTRIM( NAMES ), 'T' )
25
RTRIM
Removes blanks or characters from the end of a string.
¨ In UNICODE mode, RTRIM removes both single- and double-byte spaces from the end of a string.
If you use RTRIM to remove characters from a string, RTRIM compares the trim_set to each character in the string
argument, character by character, starting with the right side of the string. If the character in the string matches any
character in the trim_set, RTRIM removes it. RTRIM continues comparing and removing characters until it fails to find a
matching character in the trim_set. It returns the string without the matching characters.
Syntax
RTRIM( string [, trim_set] )
string Required Any string value. Passes the values you want to trim. Use operators to perform comparisons or
concatenate strings before removing blanks from the end of a string.
trim_set Optional Any string value. Passes the characters you want to remove from the end of the string. You
can also enter a text literal. However, you must enclose the characters you want to remove
from the end of the string within single quotation marks, for example, 'abc'. If you omit the
second string, the function removes blanks from the end of the first string.
RTRIM is case sensitive.
Return Value
String. The string values with the specified characters in the trim_set argument removed.
Example
The following expression removes the characters ‘re’ from the strings in a LAST_NAME column in an ALL_CUSTOMERS table:
RTRIM( ALL_CUSTOMERS.LAST_NAME, 're')
26
The following figure shows the RTRIM function in the Expression Editor that removes the characters 're' from the strings in a
LAST_NAME column in an ALL_CUSTOMERS table:
RTRIM removes ‘e’ from Page even though ‘r’ is the first character in the trim_set. This is because RTRIM searches,
character by character, for the set of characters you specify in the trim_set argument. If the last character in the string
matches the first character in the trim_set, RTRIM removes it. If, however, the last character in the string does not match,
RTRIM compares the second character in the trim_set. If the second from last character in the string matches the second
character in the trim_set, RTRIM removes it, and so on. When the character in the string fails to match the trim_set, RTRIM
returns the string and evaluates the next row.
In the last example, the last character in Nelson does not match any character in the trim_set argument, so RTRIM returns
the string 'Nelson' and evaluates the next row.
You can also remove multiple sets of characters by nesting RTRIM. For example, if you want to remove trailing blanks and
the character ‘t’ from the end of each string in a column of names, you might create an expression similar to the following:
RTRIM( RTRIM( ALL_CUSTOMERS.NAMES ), 't' )
27
REPLACECHR
Replaces characters in a string with a single character or no character. REPLACECHR searches the input string for the
characters you specify and replaces all occurrences of all characters with the new character you specify.
Syntax
REPLACECHR( CaseFlag, InputString, OldCharSet, NewChar )
CaseFlag Required Must be an integer. Determines whether the arguments in this function are case sensitive.
When CaseFlag is a number other than 0, the function is case sensitive.
When CaseFlag is a null value or 0, the function is not case sensitive.
InputString Required Must be a character string. Passes the string you want to search. If you pass a numeric value,
the function converts it to a character string.
If InputString is NULL, REPLACECHR returns NULL.
OldCharSet Required Must be a character string. The characters you want to replace. You can enter one or more
characters. You can also enter a text literal enclosed within single quotation marks, for
example, 'abc'.
If you pass a numeric value, the function converts it to a character string.
If OldCharSet is NULL or empty, REPLACECHR returns InputString.
NewChar Required Must be a character string. You can enter one character, an empty string, or NULL.
If NewChar is NULL or empty, REPLACECHR removes all occurrences of all characters in
OldCharSet in InputString.
If NewChar contains more than one character, REPLACECHR uses the first character to
replace OldCharSet.
Return Value
String.
Examples
The following expression removes the double quotes from web log data for each row in a WEBLOG column:
REPLACECHR( 0, ALL_CUSTOMERS.WEBLOG, '"', NULL )
28
The following figure shows the REPLACECHR function in the Expression Editor that removes the double quotes from web
log data for each row in a WEBLOG column in an ALL_CUSTOMERS table:
The following expression removes multiple characters for each row in the ALL_CUSTOMERS.WEBLOG column:
REPLACECHR ( 1, ALL_CUSTOMERS.WEBLOG, ']["', NULL )
The following expression changes part of the value of the customer code for each row in the
ALL_CUSTOMERS.CUSTOMER_CODE column:
REPLACECHR ( 1, ALL_CUSTOMERS.CUSTOMER_CODE, 'A', 'M' )
29
The following expression changes part of the value of the customer code for each row in the
ALL_CUSTOMERS.CUSTOMER_CODE column:
REPLACECHR ( 0, ALL_CUSTOMERS.CUSTOMER_CODE, 'A', 'M' )
The following expression changes part of the value of the customer code for each row in the CUSTOMER_CODE column:
REPLACECHR ( 1, ALL_CUSTOMERS.CUSTOMER_CODE, 'A', NULL )
The following expression removes multiple numbers for each row in the INPUT column:
REPLACECHR ( 1, ALL_CUSTOMERS.INPUT, '14', NULL )
When you want to use a single quote (') in either OldCharSet or NewChar, you must use the CHR function. The single quote
is the only character that cannot be used inside a string literal.
The following expression removes multiple characters, including the single quote, for each row in the INPUT column:
REPLACECHR (1, ALL_CUSTOMERS.INPUT, CHR(39), NULL )
REPLACESTR
Replaces characters in a string with a single character, multiple characters, or no character. REPLACESTR searches the
input string for all strings you specify and replaces them with the new string you specify.
Syntax
REPLACESTR ( CaseFlag, InputString, OldString1, [OldString2, ... OldStringN,] NewString )
CaseFlag Required Must be an integer. Determines whether the arguments in this function are case sensitive.
When CaseFlag is a number other than 0, the function is case sensitive.
30
Argument Required/ Description
Optional
InputString Required Must be a character string. Passes the strings you want to search. If you pass a numeric value,
the function converts it to a character string.
If InputString is NULL, REPLACESTR returns NULL.
OldString Required Must be a character string. The string you want to replace. You must enter at least one
OldString argument. You can enter one or more characters per OldString argument. You can
also enter a text literal enclosed within single quotation marks, for example, 'abc'.
If you pass a numeric value, the function converts it to a character string.
When REPLACESTR contains multiple OldString arguments, and one or more OldString
arguments is NULL or empty, REPLACESTR ignores the OldString argument. When all
OldString arguments are NULL or empty, REPLACESTR returns InputString.
The function replaces the characters in the OldString arguments in the order they appear in the
function. For example, if you enter multiple OldString arguments, the first OldString argument
has precedence over the second OldString argument, and the second OldString argument has
precedence over the third OldString argument. When REPLACESTR replaces a string, it
places the cursor after the replaced characters in InputString before searching for the next
match.
NewString Required Must be a character string. You can enter one character, multiple characters, an empty string,
or NULL.
If NewString is NULL or empty, REPLACESTR removes all occurrences of OldString in
InputString.
Return Value
String.
Examples
The following expression removes the double quotes and two different text strings from web log data for each row in a
WEBLOG column in an ALL_CUSTOMERS table :
REPLACESTR( 1, ALL_CUSTOMERS.WEBLOG, '"', 'GET ', ' HTTP/1.1', NULL )
31
The following figure shows the REPLACESTR function in the Expression Editor that removes the double quotes and two
different text strings for each row in a WEBLOG column in an ALL_CUSTOMERS table:
The following expression changes the title for certain values for each row in the TITLE column:
REPLACESTR ( 1, ALL_CUSTOMERS.TITLE, 'rs.', 'iss', 's.' )
The following expression changes the title for certain values for each row in the TITLE column:
REPLACESTR ( 0, ALL_CUSTOMERS.TITLE, 'rs.', 'iss', 's.' )
32
The following expression shows how the REPLACESTR function replaces multiple OldString arguments for each row in the
INPUT column:
REPLACESTR ( 1, ALL_CUSTOMERS.INPUT, 'ab', 'bc', '*' )
The following expression shows how the REPLACESTR function replaces multiple OldString arguments for each row in the
INPUT column:
REPLACESTR ( 1, ALL_CUSTOMERS.INPUT, 'ab', 'bc', 'b' )
When you want to use a single quote (') in either OldString or NewString, you must use the CHR function. Use both the CHR
and CONCAT functions to concatenate a single quote onto a string. The single quote is the only character that cannot be
used inside a string literal. Consider the following example:
CONCAT( 'Joan', CONCAT( CHR(39), 's car' ))
The following expression changes a string that includes the single quote, for each row in the INPUT column:
REPLACESTR ( 1, ALL_CUSTOMERS.INPUT, CONCAT('it', CONCAT(CHR(39), 's' )), 'its' )
ROUND (Numbers)
Rounds numbers to a specified number of digits or decimal places.
Syntax
ROUND( numeric_value [, precision] )
numeric_value Required Numeric datatype. Use operators to perform arithmetic before you round the values.
precision Optional Positive or negative integer. If you enter a positive precision, the function rounds to this
number of decimal places. For example, ROUND(12.99, 1) returns 13.0 and ROUND(15.44,
1) returns 15.4.
If you enter a negative precision, the function rounds this number of digits to the left of the
decimal point, returning an integer. For example, ROUND(12.99, -1) returns 10 and
ROUND(15.99, -1) returns 20.
33
Argument Required/ Description
Optional
If you enter decimal precision, the function rounds to the nearest integer before evaluating
the expression. For example, ROUND(12.99, 0.8) returns 13.0 because the function rounds
0.8 to 1 and then evaluates the expression.
If you omit the precision argument, the function rounds to the nearest integer, truncating the
decimal portion of the number. For example, ROUND(12.99) returns 13.
Return Value
Numeric value.
Examples
The following expression returns the values in the Price column rounded to three decimal places.
ROUND( ALL_CUSTOMERS.PRICE, 3 )
34
The following figure shows the ROUND function in the Expression Editor that returns the values in the Price column rounded
to three decimal places:
You can round digits to the left of the decimal point by passing a negative integer in the precision argument:
ROUND( ALL_CUSTOMERS.PRICE, -2 )
If you pass a decimal value in the precision argument, the function rounds it to the nearest integer before evaluating the
expression:
ROUND( ALL_CUSTOMERS.PRICE, 0.8 )
If you omit the precision argument, the function rounds to the nearest integer:
ROUND( ALL_CUSTOMERS.PRICE )
35
ALL_CUSTOMERS.PRICE RETURN VALUE
-15.99 -16.0
-18.99 -19.0
56.95 57.0
NULL NULL
SUBSTR
Returns a portion of a string. SUBSTR counts all characters, including blanks, starting at the beginning of the string.
Syntax
SUBSTR( string, start [,length] )
string Required Must be a character string. Passes the strings you want to search. If you pass a numeric value,
the function converts it to a character string.
start Required Must be an integer. The position in the string where you want to start counting. If the start
position is a positive number, SUBSTR locates the start position by counting from the
beginning of the string. If the start position is a negative number, SUBSTR locates the start
position by counting from the end of the string. If the start position is 0, SUBSTR searches
from the first character in the string.
length Optional Must be an integer greater than 0. The number of characters you want SUBSTR to return. If
you omit the length argument, SUBSTR returns all of the characters from the start position to
the end of the string. If you pass a negative integer or 0, the function returns an empty string. If
you pass a decimal, the function rounds it to the nearest integer value.
Return Value
String.
Examples
The following expressions return the area code for each row in the Phone column:
SUBSTR( ALL_CUSTOMERS.PHONE, 0, 3 )
The following figure shows the SUBSTR function in the Expression Editor that returns the area code for each row in the
Phone column in an ALL_CUSTOMERS table:
SUBSTR( ALL_CUSTOMERS.PHONE, 1, 3 )
36
ALL_CUSTOMERS.PHONE RETURN VALUE
357-687-6708 357
NULL NULL
The following expressions return the phone number without the area code for each row in the Phone column:
SUBSTR( ALL_CUSTOMERS.PHONE, 5, 8 )
You can also pass a negative start value to return the phone number for each row in the Phone column. The expression still
reads the source string from left to right when returning the result of the length argument:
SUBSTR( ALL_CUSTOMERS.PHONE, -8, 3 )
You can nest INSTR in the start or length argument to search for a specific string and return its position.
37
The following expression evaluates a string, starting from the end of the string. The expression finds the last (right-most)
space in the string and then returns all characters preceding it:
SUBSTR( ALL_CUSTOMERS.CUST_NAME,1,INSTR( ALL_CUSTOMERS.CUST_NAME,' ' ,-1,1 ) - 1 )
When the length argument is longer than the string, SUBSTR returns all the characters from the start position to the end of
the string. Consider the following example:
SUBSTR('abcd', 2, 8)
The return value is ‘bcd’. Compare this result to the following example:
SUBSTR('abcd', -2, 8)
TO_CHAR (Dates)
Converts dates to character strings. TO_CHAR also converts numeric values to strings. You can convert the date into any
format using the TO_CHAR format strings.
Syntax
TO_CHAR( date)
date Required Date/Time datatype. Passes the date values you want to convert to character strings. You can
enter any valid transformation expression.
Return Value
String.
Examples
The following expression converts the dates in the DATE_PROMISED column to text in the format MON DD YYYY:
TO_CHAR( ALL_CUSTOMERS.DATE_PROMISED, 'MON DD YYYY' )
38
The following figure describes the TO_CHAR function in the Expression Editor that converts the dates in the
DATE_PROMISED column to text in the format MON DD YYYY:
The following expressions return the day of the week for each date in a column:
TO_CHAR( ALL_CUSTOMERS.DATE_PROMISED, 'D' )
The following expression returns the day of the month for each date in a column:
TO_CHAR( ALL_CUSTOMERS.DATE_PROMISED, 'DD' )
39
ALL_CUSTOMERS.DATE_PROMISED RETURN VALUE
10-24-1997 02:12:30PM '24'
NULL NULL
The following expression returns the day of the year for each date in a column:
TO_CHAR( ALL_CUSTOMERS.DATE_PROMISED, 'DDD' )
The following expressions return the hour of the day for each date in a column:
TO_CHAR( ALL_CUSTOMERS.DATE_PROMISED, 'HH' )
TO_CHAR( ALL_CUSTOMERS.DATE_PROMISED, 'HH12' )
The following expression converts date values to MJD values expressed as strings:
TO_CHAR( ALL_CUSTOMERS.SHIP_DATE, 'J')
ALL_CUSTOMERS.SHIP_DATE RETURN_VALUE
Dec 31 1999 03:59:59PM 2451544
Jan 1 1900 01:02:03AM 2415021
ALL_CUSTOMERS.SHIP_DATE RETURN_VALUE
12/31/1999 01:02:03AM 12/31/99
09/15/1996 03:59:59PM 09/15/96
05/17/2003 12:13:14AM 05/17/03
You can also use the format string SSSSS in a TO_CHAR expression. For example, the following expression converts the
dates in the SHIP_DATE column to strings representing the total seconds since midnight:
TO_CHAR( ALL_CUSTOMERS.SHIP_DATE, 'SSSSS')
ALL_CUSTOMERS.SHIP_DATE RETURN_VALUE
12/31/1999 01:02:03AM 3783
09/15/1996 03:59:59PM 86399
In TO_CHAR expressions, the YY format string produces the same results as the RR format string.
40
The following expression converts dates to strings in the format MM/DD/YY:
TO_CHAR( ALL_CUSTOMERS.SHIP_DATE, 'MM/DD/YY')
ALL_CUSTOMERS.SHIP_DATE RETURN_VALUE
12/31/1999 01:02:03AM 12/31/99
09/15/1996 03:59:59PM 09/15/96
05/17/2003 12:13:14AM 05/17/03
The following expression returns the week of the month for each date in a column:
TO_CHAR( ALL_CUSTOMERS.DATE_PROMISED, 'W' )
The following expression returns the week of the year for each date in a column:
TO_CHAR( ALL_CUSTOMERS.DATE_PROMISED, 'WW' )
TO_DATE
Converts a character string to a Date/Time datatype. You use the TO_DATE format strings to specify the format of the
source strings.
If you are converting two-digit years with TO_DATE, use either the RR or YY format string. Do not use the YYYY format string.
Syntax
TO_DATE( string [, format] )
string Required Must be a string datatype. Passes the values that you want to convert to dates.
format Optional Enter a valid TO_DATE format string. The format string must match the parts of the string
argument. For example, if you pass the string 'Mar 15 1998 12:43:10AM', you must use the
format string 'MON DD YYYY HH12:MI:SSAM'. If you omit the format string, the string value
must be in the date format specified in the mapping specification.
Return Value
Date.
TO_DATE always returns a date and time. If you pass a string that does not have a time value, the date returned always
includes the time 00:00:00.000000000. You can map the results of this function to any target column with a datetime
datatype. If the target column precision is less than nanoseconds, the Data Integration Service truncates the datetime value
to match the precision of the target column when it writes datetime values to the target.
41
Warning: The format of the TO_DATE string must match the format string including any date separators. If it does not, the
Data Integration Service might return inaccurate values or skip the record.
Examples
The following expression returns date values for the strings in the DATE_PROMISED column. TO_DATE always returns a
date and time. If you pass a string that does not have a time value, the date returned always includes the time
00:00:00.000000000. If you run a mapping in the twentieth century, the century will be 19. In this example, the current year
on the node running the Data Integration Service is 1998. The datetime format for the target column is
MON DD YY HH24:MI SS, so the Data Integration Service truncates the datetime value to seconds when it writes to the target:
TO_DATE( ALL_CUSTOMERS.DATE_PROMISED, 'MM/DD/YY' )
The following figure shows the TO_DATE function in the Expression Editor that returns date values for the strings in a
DATE_PROMISED column in an ALL_CUSTOMERS table:
42
The following expression returns date and time values for the strings in the DATE_PROMISED column. If you pass a string
that does not have a time value, the Data Integration Service returns an error. If you run a mapping in the twentieth century,
the century will be 19. The current year on the node running the Data Integration Service is 1998:
TO_DATE( ALL_CUSTOMERS.DATE_PROMISED, 'MON DD YYYY HH12:MI:SSAM' )
The following expression converts strings in the SHIP_DATE_MJD_STRING column to date values:
TO_DATE (ALL_CUSTOMERS.SHIP_DATE_MJD_STR, 'J')
ALL_CUSTOMERS.SHIP_DATE_MJD_STR RETURN_VALUE
'2451544' Dec 31 1999 00:00:00.000000000
'2415021' Jan 1 1900 00:00:00.000000000
Because the J format string does not include the time portion of a date, the return values have the time set to
00:00:00.000000000.
The following expression converts a string to a four-digit year format. The current year is 1998:
TO_DATE( ALL_CUSTOMERS.DATE_STR, 'MM/DD/RR')
The following expression converts a string to a four-digit year format. The current year is 1998:
TO_DATE( ALL_CUSTOMERS.DATE_STR, 'MM/DD/YY')
Note: For the second row, RR returns the year 2005 and YY returns the year 1905.
The following expression converts a string to a four-digit year format. The current year is 1998:
TO_DATE( DATE_STR, 'MM/DD/Y')
The following expression converts a string to a four-digit year format. The current year is 1998:
TO_DATE( ALL_CUSTOMERS.DATE_STR, 'MM/DD/YYY')
The following expression converts strings that includes the seconds since midnight to date values:
TO_DATE( ALL_CUSTOMERS.DATE_STR, 'MM/DD/YYYY SSSSS')
ALL_CUSTOMERS.DATE_STR RETURN_VALUE
'12/31/1999 3783' 12/31/1999 01:02:03
'09/15/1996 86399' 09/15/1996 23:59:59
43
If the target accepts different date formats, use TO_DATE and IS_DATE with the DECODE function to test for acceptable
formats. For example:
DECODE( TRUE,
TRUNC (Numbers)
Truncates numbers to a specific digit. You can also use TRUNC to truncate dates.
Syntax
TRUNC( numeric_value [, precision] )
numeric_value Required Numeric datatype. Passes the values you want to truncate. You can enter any valid
expression that evaluates to a Numeric datatype.
precision Optional Can be a positive or negative integer. You can enter any valid expression that evaluates to
an integer. The integer specifies the number of digits to truncate.
If precision is a positive integer, TRUNC returns numeric_value with the number of decimal places specified by precision. If
precision is a negative integer, TRUNC changes the specified digits to the left of the decimal point to zeros. If you omit the
precision argument, TRUNC truncates the decimal portion of numeric_value and returns an integer.
If you pass a decimal precision value, the Data Integration Service rounds numeric_value to the nearest integer before
evaluating the expression.
For example, suppose the following expression is used to truncate the values in the QTY column:
TRUNC ( ALL_CUSTOMERS.QTY / 15 )
When the value for QTY = 15000000, the function returns the value 999999. The expected result is 1000000.
In the above expression, QTY is the variable value and (1/15) is the constant value.
If you use the ROUND function before truncating, the expression is evaluated as follows:
TRUNC (ROUND (ALL_CUSTOMERS.QTY/15, .99999999999999999999999999)).
Return Value
Numeric value.
44
NULL if one of the arguments is NULL.
Examples
The following expressions truncate the values in the Price column:
TRUNC( ALL_CUSTOMERS.PRICE, 3 )
The following figure shows the TRUNC function in the Expression Editor that truncates the values in the Price column in an
ALL_CUSTOMERS table:
TRUNC( ALL_CUSTOMERS.PRICE, -1 )
45
ALL_CUSTOMERS.PRICE RETURN VALUE
1235.99 1230.0
NULL NULL
TRUNC( ALL_CUSTOMERS.PRICE )
Author
Radhika Singh
Senior Technical Writer
46