0% found this document useful (0 votes)
169 views46 pages

Common Expression Editor Functions in Informatica Analyst

Uploaded by

Torsha Mazumdar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
169 views46 pages

Common Expression Editor Functions in Informatica Analyst

Uploaded by

Torsha Mazumdar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 46

Common Expression Editor Functions in

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

Expression Editor Overview


The Analyst tool provides an Expression Editor to add expression functions to rules and filters in a mapping specification.
You can add expression functions when you create a rule or apply an advanced filter to a mapping specification.

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 )

Argument Required/ Description


Optional

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.

NULL if both string values are NULL.

Nulls
If one of the strings is NULL, CONCAT ignores it and returns the other string.

If both strings are NULL, CONCAT returns NULL.

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 )

FIRST NAME LAST NAME RETURN VALUE

John Baer JohnBaer

5
FIRST NAME LAST NAME RETURN VALUE

NULL Campbell Campbell

Bobbi Apperley BobbiApperley

Jason Wood JasonWood

Dan Covington DanCovington

Greg NULL Greg

NULL NULL NULL

100 200 100200

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 )

FIRST NAME LAST NAME RETURN VALUE


John Baer John Baer
NULL Campbell Campbell (includes leading blank)
Bobbi Apperley Bobbi Apperley
Jason Wood Jason Wood
Dan Covington Dan Covington
Greg NULL Greg
NULL NULL NULL

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] )

Argument Required/ Description


Optional

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.

Default value if the search does not find 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' )

ITEM_ID RETURN VALUE


10 Flashlight
14 Regulator
17 NONE
20 Knife
25 NONE
NULL NONE
40 Tank

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.')

VAR1 VAR2 RETURN VALUE


21 47 Variable 1 was less than 23.
22 49 Variable 1 was 22!
23 49 Variable 2 was 49!
24 27 Variables were out of desired ranges.
25 50 Variable 2 was more than 30.

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 )

Argument Required/ Description


Optional

string Required Any datatype except Binary. You can enter any valid transformation expression.

Return Value
String.

NULL if a value passed to the function is NULL.

Example
The following expression capitalizes all names in the FIRST_NAME column in an ALL_CUSTOMERS table:
INITCAP( ALL_CUSTOMERS.FIRST_NAME )

FIRST_NAME RETURN VALUE


ramona Ramona
18-albert 18-Albert
NULL NULL
?!SAM ?!Sam
THOMAS Thomas
PierRe Pierre

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 ]]] )

Argument Required/ Description


Optional

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.

0 if the search is unsuccessful.

NULL if a value passed to the function is NULL.

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' )

ALL_CUSTOMERS.COMPANY RETURN VALUE


Blue Fin Aqua Center 13
Maco Shark Shop 2
Scuba Gear 5
Frank's Dive Shop 3
VIP Diving Club 0

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 )

ALL_CUSTOMERS.COMPANY RETURN VALUE


Blue Fin Aqua Center 0
Maco Shark Shop 8
Scuba Gear 9
Frank's Dive Shop 0
VIP Diving Club 0

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 )

COMPANY RETURN VALUE


Blue Fin Aqua Center 0
Maco Shark Shop 2
Scuba Gear 5

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 )

ALL_CUSTOMERS.COMPANY RETURN VALUE


Blue Fin Aqua Center 1
Maco Shark Shop 0
Scuba Gear 0
Frank's Dive Shop 0
VIP Diving Club 0

Using Nested INSTR


You can nest the INSTR function within other functions to accomplish more complex tasks.

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 ))

ALL_CUSTOMERS.CUST_NAME RETURN VALUE


PATRICIA JONES PATRICIA
MARY ELLEN SHAH MARY ELLEN

The following expression removes the character '#' from a string:


SUBSTR( ALL_CUSTOMERS.CUST_ID, 1, INSTR(ALL_CUSTOMERS.CUST_ID, '#')-1 ) || SUBSTR( ALL_CUSTOMERS.CUST_ID,
INSTR(ALL_CUSTOMERS.CUST_ID, '#')+1 )

CUST_ID RETURN VALUE


ID#33 ID33
#A3577 A3577
SS #712403399 SS 712403399

ISNULL
Returns whether a value is NULL. ISNULL evaluates an empty string as FALSE.

Note: To test for empty strings, use LENGTH.

Syntax
ISNULL( value )

Argument Required/ Description


Optional

value Required Any datatype except Binary. Passes the rows you want to evaluate.

Return Value
TRUE (1) if the value is NULL.

FALSE (0) if the value is not 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 )

ALL_CUSTOMERS.ITEM_NAME RETURN VALUE


Flashlight 0 (FALSE)
NULL 1 (TRUE)
Regulator system 0 (FALSE)
'' 0 (FALSE) Empty string is not NULL

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.

A valid number consists of the following parts:

¨ Optional space before the number

¨ Optional sign (+/-)

¨ One or more digits with an optional decimal point

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 following numbers are all valid:


' 100 '
' +100'
'-100'
'-3.45e+32'
'+3.45E-32'
'+3.45d+32' (Windows only)
'+3.45D-32' (Windows only)
'.6804'

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 )

Argument Required/ Description


Optional

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.

FALSE (0) if the row is not a valid number.

NULL if a value in the expression is NULL.

Examples
The following expression checks for valid numbers in an ITEM_PRICE column in an ALL_CUSTOMERS table:
IS_NUMBER( ALL_CUSTOMERS.ITEM_PRICE )

ALL_CUSTOMERS.ITEM_PRICE RETURN VALUE


'123.00' 1 (True)
'-3.45e+3' 1 (True)
'-3.45D-3' 1 (True - Windows only)
'-3.45d-3' 0 (False - UNIX only)
'3.45E-' 0 (False) Incomplete number
' ' 0 (False) Consists entirely of blanks
'' 0 (False) Empty string
'+123abc' 0 (False)
' 123' 1 (True) Leading white blanks
'123 ' 1 (True) Trailing white blanks
'ABC' 0 (False)
'-ABC' 0 (False)
NULL NULL

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 )

ALL_CUSTOMERS.ITEM_PRICE RETURN VALUE


'123.00' 123
'-3.45e+3' -3450
'3.45E-3' 0.00345
' ' 0.00 Consists entirely of blanks
'' 0.00 Empty string
'+123abc' 0.00
'' 123ABC' 0.00
'ABC' 0.00
'-ABC' 0.00
NULL NULL

16
LOWER
Converts uppercase string characters to lowercase.

Syntax
LOWER( string )

Argument Required/ Description


Optional

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.

NULL if a value in the selected column is NULL.

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 )

ALL_CUSTOMERS.FIRST_NAME RETURN VALUE


antonia antonia
NULL NULL
THOMAS thomas
PierRe pierre
BERNICE bernice

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 )

Argument Required/ Description


Optional

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.

NULL if a value passed to the function is NULL.

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 )

ALL_CUSTOMERS.FIRST_NAME RETURN VALUE


Ramona RAMONA
NULL NULL
THOMAS THOMAS
PierRe PIERRE
Bernice BERNICE

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] )

Argument Required/ Description


Optional

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.

NULL if a value passed to the function is NULL or if length is a negative number.

Examples
The following expression standardizes numbers to six digits by padding them with leading zeros.
LPAD( ALL_CUSTOMERS.PART_NUM, 6, '0')

ALL_CUSTOMERS.PART_NUM RETURN VALUE


702 000702
1 000001
0553 000553
484834 484834

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, '*..*' )

ALL_CUSTOMERS.ITEM_NAME RETURN VALUE


Flashlight *..**.Flashlight
Compass *..**..**Compass
Regulator System Regulator System
Safety Knife *..*Safety Knife

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] )

Argument Required/ Description


Optional

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.

NULL if a value passed to the function is NULL or if length is a negative number.

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, '.')

ALL_CUSTOMERS.ITEM_NAME RETURN VALUE


Flashlight Flashlight......
Compass Compass.........
Regulator System Regulator System
Safety Knife Safety Knife....

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, '*..*' )

ALL_CUSTOMERS.ITEM_NAME RETURN VALUE


Flashlight Flashlight*..**.
Compass Compass*..**..**
Regulator System Regulator System
Safety Knife Safety Knife*..*

LTRIM
Removes blanks or characters from the beginning of a string.

If you do not specify a trim_set parameter in the expression:

¨ In UNICODE mode, LTRIM removes both single- and double-byte spaces from the beginning of a string.

¨ In ASCII mode, LTRIM removes only single-byte spaces.

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] )

Arguments Required/ Description


Optional

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.')

ALL_CUSTOMERS.LAST_NAME RETURN VALUE


Nelson Nelson
Osborne Osborne
NULL NULL
S. MacDonald MacDonald
Sawyer awyer
H. Bender H. Bender
Steadman teadman

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.

Tips for LTRIM


Use RTRIM and LTRIM with || or CONCAT to remove leading and trailing blanks after you concatenate two strings.

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.

If you do not specify a trim_set parameter in the expression:

¨ In UNICODE mode, RTRIM removes both single- and double-byte spaces from the end of a string.

¨ In ASCII mode, RTRIM removes only single-byte spaces.

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] )

Argument Required/ Description


Optional

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.

NULL if a value passed to the function is NULL.

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')

ALL_CUSTOMERS.LAST_NAME RETURN VALUE


Nelson Nelson
Page Pag
Osborne Osborn
NULL NULL
Sawyer Sawy
H. Bender H. Bend
Steadman Steadman

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.

Tips for RTRIM


Use RTRIM and LTRIM with || or CONCAT to remove leading and trailing blanks after you concatenate two strings.

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 )

Argument Required/ Description


Optional

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.

Empty string if REPLACECHR removes all characters in InputString.

NULL if InputString is NULL.

InputString if OldCharSet is NULL or empty.

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 )

ALL_CUSTOMERS.WEBLOG RETURN VALUE


"GET /news/index.html HTTP/1.1" GET /news/index.html HTTP/1.1
"GET /companyinfo/index.html HTTP/1.1" GET /companyinfo/index.html HTTP/1.1
GET /companyinfo/index.html HTTP/1.1 GET /companyinfo/index.html HTTP/1.1
NULL 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 )

ALL_CUSTOMERS.WEBLOG RETURN VALUE


[29/Oct/2001:14:13:50 -0700] 29/Oct/2001:14:13:50 -0700
[31/Oct/2000:19:45:46 -0700] "GET /news/index.html HTTP/31/Oct/2000:19:45:46 -0700 GET /news/index.html
1.1" HTTP/1.1
[01/Nov/2000:10:51:31 -0700] "GET /news/index.html HTTP/01/Nov/2000:10:51:31 -0700 GET /news/index.html
1.1" HTTP/1.1
NULL 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' )

ALL_CUSTOMERS.CUSTOMER_CODE RETURN VALUE


ABA MBM
abA abM
BBC BBC
ACC MCC
NULL NULL

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' )

ALL_CUSTOMERS.CUSTOMER_CODE RETURN VALUE


ABA MBM
abA MbM
BBC BBC
ACC MCC

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 )

CUSTOMER_CODE RETURN VALUE


ABA B
BBC BBC
ACC CC
AAA [empty string]
aaa aaa
NULL NULL

The following expression removes multiple numbers for each row in the INPUT column:
REPLACECHR ( 1, ALL_CUSTOMERS.INPUT, '14', NULL )

ALL_CUSTOMERS.INPUT RETURN VALUE


12345 235
4141 NULL
111115 5
NULL 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 )

ALL_CUSTOMERS.INPUT RETURN VALUE


'Tom Smith' 'Laura Jones' Tom Smith Laura Jones
Tom's Toms
NULL 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 )

Argument Required/ Description


Optional

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

When CaseFlag is a null value or 0, the function is not case sensitive.

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.

Empty string if REPLACESTR removes all characters in InputString.

NULL if InputString is NULL.

InputString if all OldString arguments are NULL or empty.

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 )

ALL_CUSTOMERS.WEBLOG RETURN VALUE


"GET /news/index.html HTTP/1.1" /news/index.html
"GET /companyinfo/index.html HTTP/1.1" /companyinfo/index.html
GET /companyinfo/index.html /companyinfo/index.html
GET [empty string]
NULL 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.' )

ALL_CUSTOMERS.TITLE RETURN VALUE


Mrs. Ms.
Miss Ms.
Mr. Mr.
MRS. MRS.

The following expression changes the title for certain values for each row in the TITLE column:
REPLACESTR ( 0, ALL_CUSTOMERS.TITLE, 'rs.', 'iss', 's.' )

ALL_CUSTOMERS.TITLE RETURN VALUE


Mrs. Ms.
MRS. Ms.

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', '*' )

ALL_CUSTOMERS.INPUT RETURN VALUE


abc *c
abbc **
abbbbc *bb*
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' )

ALL_CUSTOMERS.INPUT RETURN VALUE


ab b
bc b
abc bc
abbc bb
abbcc bbc

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 return value is:


Joan'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' )

ALL_CUSTOMERS.INPUT RETURN VALUE


it's its
mit's mits
mits mits
mits' mits'

ROUND (Numbers)
Rounds numbers to a specified number of digits or decimal places.

Syntax
ROUND( numeric_value [, precision] )

Argument Required/ Description


Optional

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.

If one of the arguments is NULL, ROUND returns NULL.

Examples
The following expression returns the values in the Price column rounded to three decimal places.
ROUND( ALL_CUSTOMERS.PRICE, 3 )

ALL_CUSTOMERS.PRICE RETURN VALUE


12.9936 12.994
15.9949 15.995
-18.8678 -18.868
56.9561 56.956
NULL NULL

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 )

ALL_CUSTOMERS.PRICE RETURN VALUE


13242.99 13200.0
1435.99 1400.0
-108.95 -100.0
NULL NULL

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 )

ALL_CUSTOMERS.PRICE RETURN VALUE


12.99 13.0
56.34 56.3
NULL NULL

If you omit the precision argument, the function rounds to the nearest integer:
ROUND( ALL_CUSTOMERS.PRICE )

ALL_CUSTOMERS.PRICE RETURN VALUE


12.99 13.0

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] )

Argument Required/ Description


Optional

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.

Empty string if you pass a negative or 0 length value.

NULL if a value passed to the function is NULL.

Examples
The following expressions return the area code for each row in the Phone column:
SUBSTR( ALL_CUSTOMERS.PHONE, 0, 3 )

ALL_CUSTOMERS.PHONE RETURN VALUE


809-555-0269 809
357-687-6708 357
NULL NULL

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 )

ALL_CUSTOMERS.PHONE RETURN VALUE


809-555-3915 809

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 )

ALL_CUSTOMERS.PHONE RETURN VALUE


808-555-0269 555-0269
809-555-3915 555-3915
357-687-6708 687-6708
NULL NULL

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 )

ALL_CUSTOMERS.PHONE RETURN VALUE


808-555-0269 555
809-555-3915 555
357-687-6708 687
NULL NULL

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 )

ALL_CUSTOMERS.CUST_NAME RETURN VALUE


PATRICIA JONES PATRICIA
MARY ELLEN SHAH MARY ELLEN

The following expression removes the character '#' from a string:


SUBSTR( ALL_CUSTOMERS.CUST_ID, 1, INSTR(ALL_CUSTOMERS.CUST_ID, '#')-1 ) || SUBSTR( ALL_CUSTOMERS.CUST_ID,
INSTR(ALL_CUSTOMERS.CUST_ID, '#')+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)

The return value is ‘cd’.

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)

Argument Required/ Description


Optional

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.

NULL if a value passed to the function is NULL.

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' )

ALL_CUSTOMERS.DATE_PROMISED RETURN VALUE


Apr 1 1998 12:00:10AM 'Apr 01 1998'
Feb 22 1998 01:31:10PM 'Feb 22 1998'
Oct 24 1998 02:12:30PM 'Oct 24 1998'
NULL NULL

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' )

ALL_CUSTOMERS.DATE_PROMISED RETURN VALUE


04-01-1997 12:00:10AM '3'
02-22-1997 01:31:10PM '7'
10-24-1997 02:12:30PM '6'
NULL NULL

TO_CHAR( ALL_CUSTOMERS.DATE_PROMISED, 'DAY' )

ALL_CUSTOMERS.DATE_PROMISED RETURN VALUE


04-01-1997 12:00:10AM 'Tuesday'
02-22-1997 01:31:10PM 'Saturday'
10-24-1997 02:12:30PM 'Friday'
NULL NULL

The following expression returns the day of the month for each date in a column:
TO_CHAR( ALL_CUSTOMERS.DATE_PROMISED, 'DD' )

ALL_CUSTOMERS.DATE_PROMISED RETURN VALUE


04-01-1997 12:00:10AM '01'
02-22-1997 01:31:10PM '22'

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' )

ALL_CUSTOMERS.DATE_PROMISED RETURN VALUE


04-01-1997 12:00:10AM '091'
02-22-1997 01:31:10PM '053'
10-24-1997 02:12:30PM '297'
NULL NULL

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' )

ALL_CUSTOMERS.DATE_PROMISED RETURN VALUE


04-01-1997 12:00:10AM '12'
02-22-1997 01:31:10PM '01'
10-24-1997 02:12:30PM '02'
NULL NULL

TO_CHAR( ALL_CUSTOMERS.DATE_PROMISED, 'HH24' )

ALL_CUSTOMERS.DATE_PROMISED RETURN VALUE


04-01-1997 12:00:10AM '00'
02-22-1997 01:31:10PM '13'
10-24-1997 11:12:30PM '23'
NULL NULL

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

The following expression converts dates to strings in the format MM/DD/YY:


TO_CHAR( ALL_CUSTOMERS.SHIP_DATE, 'MM/DD/RR')

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' )

ALL_CUSTOMERS.DATE_PROMISED RETURN VALUE


04-01-1997 12:00:10AM '01'
02-22-1997 01:31:10AM '04'
10-24-1997 02:12:30PM '04'
NULL NULL

The following expression returns the week of the year for each date in a column:
TO_CHAR( ALL_CUSTOMERS.DATE_PROMISED, 'WW' )

ALL_CUSTOMERS.DATE_PROMISED RETURN VALUE


04-01-1997 12:00:10PM '18'
02-22-1997 01:31:10AM '08'
10-24-1997 02:12:30AM '43'
NULL NULL

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.

The output column must be Date/Time for TO_DATE expressions.

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] )

Argument Required/ Description


Optional

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.

NULL if you pass a null value to this function.

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' )

ALL_CUSTOMERS.DATE_PROMISED RETURN VALUE


'01/22/98' Jan 22 1998 00:00:00
'05/03/98' May 3 1998 00:00:00
'11/10/98' Nov 10 1998 00:00:00
'10/19/98' Oct 19 1998 00:00:00
NULL NULL

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' )

ALL_CUSTOMERS.DATE_PROMISED RETURN VALUE


'Jan 22 1998 02:14:56PM' Jan 22 1998 02:14:56PM
'Mar 15 1998 11:11:11AM' Mar 15 1998 11:11:11AM
'Jun 18 1998 10:10:10PM' Jun 18 1998 10:10:10PM
'October 19 1998' Error. Integration Service skips this row.
NULL NULL

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')

ALL_CUSTOMERS.DATE_STR RETURN VALUE


'04/01/98' 04/01/1998 00:00:00.000000000
'08/17/05' 08/17/2005 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/YY')

ALL_CUSTOMERS.DATE_STR RETURN VALUE


'04/01/98' 04/01/1998 00:00:00.000000000
'08/17/05' 08/17/1905 00:00:00.000000000

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')

ALL_CUSTOMERS.DATE_STR RETURN VALUE


'04/01/8' 04/01/1998 00:00:00.000000000
'08/17/5' 08/17/1995 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/YYY')

ALL_CUSTOMERS.DATE_STR RETURN VALUE


'04/01/998' 04/01/1998 00:00:00.000000000
'08/17/995' 08/17/1995 00:00:00.000000000

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,

--test first format


IS_DATE( ALL_CUSTOMERS.CLOSE_DATE,'MM/DD/YYYY HH24:MI:SS' ),

--if true, convert to date


TO_DATE( ALL_CUSTOMERS.CLOSE_DATE,'MM/DD/YYYY HH24:MI:SS' ),

--test second format; if true, convert to date


IS_DATE( ALL_CUSTOMERS.CLOSE_DATE,'MM/DD/YYYY'), TO_DATE( CLOSE_DATE,'MM/DD/YYYY' ),

--test third format; if true, convert to date


IS_DATE( ALL_CUSTOMERS.CLOSE_DATE,'MON DD YYYY'), TO_DATE( CLOSE_DATE,'MON DD YYYY'),

--if none of the above


ERROR( 'NOT A VALID DATE') )

TRUNC (Numbers)
Truncates numbers to a specific digit. You can also use TRUNC to truncate dates.

Syntax
TRUNC( numeric_value [, precision] )

Argument Required/ Description


Optional

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.

When QTY = 15000000, the expression is evaluated as follows:


TRUNC ( 15000000 * (1/15)
TRUNC ( 15000000 * (1/15)
= TRUNC ( 15000000 * 0.0666666666666666)
= TRUNC ( 15000000 * 0.0666666666666666)
= TRUNC ( 999999.99999999)
= 999999

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 )

ALL_CUSTOMERS.PRICE RETURN VALUE


12.9995 12.999
-18.8652 -18.865
56.9563 56.956
15.9928 15.992
NULL NULL

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 )

ALL_CUSTOMERS.PRICE RETURN VALUE


12.99 10.0
-187.86 -180.0
56.95 50.0

45
ALL_CUSTOMERS.PRICE RETURN VALUE
1235.99 1230.0
NULL NULL

TRUNC( ALL_CUSTOMERS.PRICE )

ALL_CUSTOMERS.PRICE RETURN VALUE


12.99 12.0
-18.99 -18.0
56.95 56.0
15.99 15.0
NULL NULL

Author
Radhika Singh
Senior Technical Writer

46

You might also like