Character functions are used to manipulate values returned on character fields.
The following table provides a list of the character functions that you can use in queries. The Oracle Function column contains the function you will need to use if you are using an Oracle schema. The SQL Server Function column contains the function you will need to use if you are using a SQL Server database. Selecting a link in the table will open the appropriate example drop-down within this topic.
In some cases, there is no SQL Server equivalent of an Oracle function. In these cases, the SQL Server Function column contains an empty, shaded cell.
Description | Oracle Function | SQL Server Function |
---|---|---|
Convert character to ASCII | ASCII | ASCII |
Convert ASCII to character | CHR | CHAR |
Convert string if null | NVL | ISNULL |
Translate character string | TRANSLATE | None |
Combintion of letters and numbers that use the Soundex Indexing System to represent the character string (See note) | SOUNDEX | SOUNDEX |
Convert characters to uppercase | UPPER | UPPER |
Convert characters to lowercase | LOWER | LOWER |
Capitalize first letter of each word in string | INITCAP | None |
Greatest character string in list | GREATEST | None |
Least character string in list | LEAST | None |
String concatenate | CONCAT | (expression + expression) |
Substring | SUBSTR | SUBSTRING |
Return starting point of character in character string (from left) | INSTR | CHARINDEX |
Length of character string in list | LENGTH | LEN or DATALENGTH |
Pad left side of character string | LPAD | None |
Remove leading blanks | LTRIM | LTRIM |
Remove trailing blanks | RTRIM | RTRIM |
Replace characters | REPLACE | STUFF |
String of repeated spaces | RPAD | SPACE |
Suppose that you want to view the Failure ID of the failure associated with each piece of equipment or location in your database. Failure IDs are stored with a dash in the syntax, and you want to display them with a double colon instead of the dash.
In this case, you might configure a query on the Asset and Failure families, joined via the Asset Has Failure relationship, and add the Asset ID and Failure ID fields to the query.
In this example, to return the Failure IDs and replace the dash with a double colon, you would configure an expression using the REPLACE function. You would also configure the alias to ensure that the column displays the text Failure ID.
In this case, the expression syntax is:
The syntax indicates that you want to replace the dash (-) with a double colon (::).
Suppose that you recently implemented a new process for storing Failure IDs in Failure records. Previously, Failure IDs were formatted as FAIL-n, where n indicated the number of the failure. For example, the tenth failure that was recorded contained a Failure ID of FAIL-10. You have decided that you want all failures to contain four digits and that zeroes should be used as placeholders if the failure is not the 1000th failure or later. For example, the tenth failure should be recorded as FAIL-0010 instead of FAIL-10.
You know that a Failure ID in the new format will contain nine characters, where the dash (-) is considered a character. You want to see which Failure records contain IDs with fewer than nine characters. In this case, you might configure a query on the Failure family, and add the Failure ID field and the ENTY_KEY system field to the query twice each.
In this example, to display each Failure record with a Failure ID that contains fewer than nine characters, you would configure an expression using the LEN function. You would also configure the alias to indicate that the column displays the number of characters in the Failure ID.
In this case, the expression syntax is:
The query also includes criteria on this column that indicates that the results should display only Failure records where the Failure ID contains fewer than nine characters.
A hyperlink has been added to the Failure ID field so that you can open from the results each Failure record in the Record Manager and update the Failure ID. Because the query is running in unformatted mode and the hyperlink includes the EntityKey parameter and the FamilyKey parameter, the Entity Key field and the Family Key field are also included in the query.
Note: You can use the LEN syntax on a SQL Server database only. To use this function on an Oracle schema, use LENGTH instead of LEN.
The following table lists more examples of using Character functions:
Function | Description | Example | Stored Value | Result |
---|---|---|---|---|
CONCAT | Concatenates two field values and displays the result. | CONCAT([Asset)ID], [Asset Type]) |
Asset ID: T-101 Asset Type: Tank |
T-101Tank |
& | Concatenates two or more field values and adds delimiters between the values. | [Asset ID] &':' & [Asset Type] |
Asset ID: T-101 Asset Type: Tank |
T-101:Tank |
LOWER | Displays the value in all lowercase letters. | LOWER([Asset Type]) | Tank | Tank |
UPPER | Displays the value in all uppercase letters. | UPPER([Asset Type]) | Tank | Tank |
SUBSTR | Displays a specific number of characters depending on the starting point you specify and the number of characters that you specify should be returned. |
SUBSTR([Asset ID],0,3) Zero (0) specifies the starting point (from left to right) and three (3) specifies the number of characters after the starting point that you want to display. |
PMP-101 | PMP |
NVL | Displays a specified value when a null value is found. | NVL([Asset Type],'No Value Listed') | Asset Type field contains a null value | No Value Listed |
INITCAP | Displays the value with the first letter of each word capitalized. | INITCAP([Failure Mode]) | bearing failure | bearing failure |
LTRIM | Displays the value with the specified characters removed from the beginning (left) of the string. | LTRIM([PhoneNumber], '(540)-') | (540) 344-9205 | 344-9205 |
RTRIM | Displays the value with the specified characters removed from the end (right) of the string. | RTRIM([Failure ID], '-0123456789') | FAIL-1234 | FAIL |
Copyright © 2018 General Electric Company. All rights reserved.