You are on page 1of 4

1 Character Functions:

1.1 LENGTH: The LENGTH function returns the number of characters in a string, including trailing blanks. It is available in the Designer and the Workflow Manager. LENGTH (string) Example: The following expression returns the length of each customer name: LENGTH (CUSTOMER_NAME) CUSTOMER_NAME Ramesh RAKESH BHERA NULL RETURN VALUE 6 11

1.2 LPAD:

The LPAD function adds a set of blanks or characters to the beginning of a string, to set a string to a specified length. It is available in the Designer and the Workflow Manager.

LPAD (first_string, length [, second_string])

Example: The following expression standardizes numbers to five digits by padding them with leading zeros.

LPAD (NUM, 5, '0') LPAD (COLUMN_NAME, 10, 'a')

NUM 1 250 313646 RETURN VALUE 00001 00250 aaaa313646

1.4 RPAD: The RPAD function converts a string to a specified length by adding blanks or characters to the end of the string. It is available in the Designer and the Workflow Manager. RPAD( first_string, length [, second_string ] )

Example: The following expression returns the string with a length of 5 characters, appending the string ':' to the end of each word: RPAD (WORD, 5, ':) WORD Date Time RETURN VALUE Date: Time:

1.3 LTRIM: The LTRIM function removes blanks or characters from the beginning of a string. It is available in the Designer and the Workflow Manager. LTRIM (string [, trim_set]) LTRIM (string) removes the leading spaces or blanks from the string. When LTRIM function is used with a trim set, which is optional, it removes the characters in the trim set from the string. Example : The following expression removes the leading zeroes in the port ITEM_CODE. LTRIM (ITEM_CODE,'0') ITEM_CODE 006 0803 aaaa313646 RETURN VALUE 6 803 313646 * The LTRIM function can be nested when needed to remove multiple characters.

1.5 RTRIM:

The RTRIM function removes blanks or characters from the end of a string. It is available in the Designer and the Workflow Manager. RTRIM (string [, trim_set]) The RTRIM function can be combined with the LENGTH function if the trailing blanks are to be ignored. It can also be nested when needed to remove multiple characters. RTRIM (string) removes the trailing spaces or blanks from the string. When RTRIM function is used with a trimset, which is optional, it removes the characters in the trimset from the string. For example, RTRIM (ITEM_CODE,'10') The above expression removes the characters 10 in the port ITEM_CODE.

ITEM_CODE 0610 380 RETURN VALUE 06 38 In the second example the function removes the trailing zero since the RTRIM compares the first character in the trimset with the last character of the string, since it does not match it takes the second character in the trimset and compares with last character of the string. Since it matches it removes it. select substr('ramesh',2,2) from dual; select substr('ramesh',2,length('ramesh')) from dual; select lpad('ramesh',10,'a') from dual;

1.6 SUBSTR: The SUBSTR function returns a portion of a string. It is available in the Designer and the Workflow Manager. SUBSTR( string, start [, length ] ) The SUBSTR may not give the desired result if the string on which it is used is not trimmed. Though it is always a good practice to trim the strings before using them in any expression, it becomes extremely important to trim them if they are used in a SUBSTR function. For example, if there is a function SUBSTR (NAME, 2,2) It will not return the 2,3 characters of the NAME if the port has leading spaces. In this case LTRIM becomes essential. SUBSTR(LTRIM(NAME),2,2) The SUBSTR function can also be used to get the last few characters as described below. SUBSTR(NAME,-3,3) This function will return the last three characters of the string. But it may not return the required last three characters if the port has trailing blanks, hence RTRIM is essential. SUBSTR(RTRIM(NAME),-3,3) Hence it is always better to trim the strings before using them in a SUBSTR function. SUBSTR(LTRIM(RTRIM(NAME)),3,2) The above expression will get the 3,4 character of the port NAME irrespective of whether the port has leading or trailing blanks or not. 2 Conversion Functions: 2.1 TO_CHAR: The TO_CHAR function converts numeric values and dates to text strings. It is available in the Designer and the Workflow Manager. TO_CHAR( numeric_value ) TO_CHAR (date [, format ] ) Example : The following expression converts the values in the SALES port to text:

TO_CHAR (SALES ) SALES 1800.03 -22.57891 RETURN VALUE '1800.03'

'-22.57891' The following expression converts the dates in the DATE_PROMISED port to text in the format MON DD YYYY: TO_CHAR (DATE_PROMISED, 'MON DD YYYY' ) DATE_PROMISED Apr 1 1998 12:00:10AM RETURN VALUE 'Apr 01 1998' If we omit the format_string argument, TO_CHAR returns a string in the default date format MM/DD/YYYY. SYSDATE ------------------------20-FEB-13

We can use Conversion functions with DATE functions in order to do some calculations. The following composite expression converts the string DATE_PROMISED to date, adds 1 to it and then converts the same to text string with the format YYYYMMDD. TO_CHAR(ADD_TO_DATE(TO_DATE(DATE_PROMISED),'DD',1),'YYYYMMDD') Test functions can also be used with Conversion functions. The following expression uses IS_DATE along with TO_CHAR. IS_DATE(TO_CHAR(DATE_PROMISED,'YYYYMMDD')) * TO_CHAR returns NULL if invalid Date is passed to the function.

You might also like