Character and Binary Functions
All string functions support Unicode characters. Functions that transform character case are locale-sensitive.
These functions support the UTF-8 format:
- RTRIM
- LTRIM
- LEFT
- RIGHT
- TRIM
- TRANSLATE
- RPAD
- LPAD
- SUBSTRING
Index position values for character and string functions begin at position 1. For example, the "H" in the string "Hello" is at position 1.
ASCII
Returns the ASCII code value of the leftmost character of the character value.
The ASCII function only supports ASCII characters in the input argument.
Syntax
Example
Output:97
Example
Output:98
BIT_LENGTH
Returns the length of the character value in bits.
Syntax
Example
Output:8
Example
Output:16
Example
Output:24
BTRIM
Alias for TRIM.
CHR
Converts an integer value to a string.
The value is first sign-extended to 8 bytes. Then, if it can be represented as 1 byte, a string is returned with that one byte.
Otherwise, a string is returned of length 2 bytes, 4 bytes, or 8 bytes with the bytes set to the big-endian representation of the integer, depending on how many high order zero bytes there are in the integer.
Syntax
Example
Output:a
CHAR_LENGTH
Alias for LENGTH.
CHARACTER_LENGTH
Alias for LENGTH.
CONCAT
Concatenates two or more values, all of which must be binary, hash, or string data types.
For strings, as long as one argument is a character value, the other arguments are implicitly cast to a character value.
Syntax
Example
Output:ocient data warehouse
Example
Output:ocient data warehouse
ENDSWITH
Returns true if x ends with y and false otherwise.
Syntax
Example
Output:true
Example
Output:false
Example
Output:true
INITCAP
For each word in the specified string, capitalize the first character if it is alphabetic. The system defines words as alphanumeric strings separated by non-alphanumeric characters. The system converts all other alphabetic characters to lowercase.
Syntaxes
Example
Output:Ocient
INSTR
Returns the index position of the first occurrence where the character value char_substring appears in the character value char by ignoring the case.
Syntax
Example
Output:1
Output:8
JSON_EXTRACT_PATH_TEXT
Returns the value for the key-value pair referenced by a series of path elements in a JSON string.
Syntax
Examples
Extract Values from Nested Paths
This example extracts the value based on two specified paths in the JSON string, n4 and n6.
Output:"circle"
Return NULL from Invalid JSON
In this example, the query requests the same nested paths, but the JSON is invalid because all of the keys lack quotation marks.
The query returns NULL because the null_if_invalid argument equals TRUE.
Output:NULL
LCASE
Alias for LOWER.
LEFT
Return the number of characters in the string equal of the value integer. If integer is negative, the function returns all but the last integer characters.
Syntax
Example
Output:ocient d
Example
Output:ocient data wareho
LENGTH
Alias for CHAR_LENGTH and CHARACTER_LENGTH.
Returns the length of the value. For character data types, this value is in terms of characters. For binary data types, this value is in terms of bytes.
Syntax
Example
Output:21
LOCATE
Alias for POSITION.
Returns the index position of the first occurrence of the character value substring in the character value string.
Optionally, you can also include an additional value offset to offset the LOCATE function by the specified number of spaces.
Index positions begin at 1.
Syntax
Example
Output:13
Example
Output:4
Example
In this example, the index starts at position 5. This means the function skips the initial 'e' in the string. Instead, it returns the second e at index position 15.
Output:15
LOWER
Alias for LCASE.
Convert string to lowercase.
Syntax
Example
Output:ocient
Example
Output:ocient
LPAD
Pad the input text to the specified length with the pad string on the left side. If text is longer than length, it is truncated to length characters. If the argument pad is not provided, the space character is used.
Syntax
Example
Output:ababababaocient data warehouse
Example
Output:ocient
LTRIM
Removes leading blanks from the string value string.
Alternatively, you can specify a second string value trim_character. If you specify the trim_character value, the LTRIM function removes all leading instances of the trim_character value from the string.
Syntax
Example
Output:ocient
Example
Output:ocient
Example
In this example, all characters 'abeo ' are removed from the left side of the string.
Output:cient
MD5
Returns the hexadecimal string (all lowercase) representing the md5 hash of char.
Syntax
Example
Output:438f03cf6e9ddf8793e02db25f2d2f88
MID
Alias for SUBSTRING.
OCTET_LENGTH
Returns the length in bytes of a character or binary value.
Syntax
Example
Output:1
Example
Output:6
POSITION
Alias for LOCATE.
REGEXP_COUNT
Searches a string for all occurrences of a regular expression pattern. The function returns an integer representing the number of times the regular expression pattern occurs in the string.
Syntax
Example
This example searches the 'ABABDaSGRESaB' string for the count of occurrences of the 'AB' string by ignoring the case sensitivity. The search starts at position 1.
Output:3
REGEXP_INSTR
Searches a string using a regular expression pattern and returns an integer representing the start position or end position of the substring that matches.
The function returns 0 if no match is found.
The REGEXP_INSTR function is similar to the POSITION function, but it allows greater precision with regular expressions.
Syntax
1: Returns the end position of the match+1.
The function treats any nonzero integer value as1.
The default value is0. | |parameters|CHAR| Optional.
A string containing one or more characters that represents the regular expression options for pattern matching. Supported options are:c— Perform case-sensitive matching. The Ocient System enables this type of matching by default.i— Perform case-insensitive matching.e— Extract the substring using a regular expression subpattern. This subpattern is enclosed in parentheses in the regular expression.
The function uses the full regular expression pattern for the match but returns only the first subpattern match.p— Interpret the pattern using the Perl Compatible Regular Expression (PCRE) dialect. For details, see PCRE. The Ocient System enables this interpretation by default. |
Example
The query searches the website URL for the substring preceded by the # character. The function includes optional arguments to start the search at position 9 and match the first occurrence. The last specified optional argument directs the function to return the ending position of the matching substring.
Output:57
REGEXP_REPLACE
Searches a string for all occurrences of a regular expression pattern. The function replaces every match occurrence of the pattern with a new string.
The REGEXP_REPLACE function is similar to the REPLACE and TRANSLATE functions, but it allows greater precision with regular expressions.
Syntax
Examples
Replace Text Using a Substring
The query replaces the matching substring '#J28jB' with the characters '#0FqD_'. The search begins at position 9.
Output:https://docs.ocient.com/character-binary-functions#0FqD_
Replace Text Using Multiple Capture Groups
This example uses three capture groups to take an unformatted phone number and convert it into the (XXX) XXX-XXXX format. The replace_string argument references each capture group as $1, $2, and $3.
Output:(555) 867-5309
REGEXP_SUBSTR
Returns one substring from a string that matches a specified regular expression pattern.
REGEXP_SUBSTR is similar to the SUBSTR function, but it allows greater precision with regular expressions.
If the pattern produces no matches, the function returns an empty string.
Syntax
Example
The query returns the first occurrence of the #J28jB string by using the regular expression pattern '#\w+'. The search starts at position 9.
Output:#J28jB
REPEAT
Repeats the char string num times without spaces.
Syntax
Example
Repeat the a string five times.
Output:aaaaa
REPLACE
Replaces all occurrences of substr_to_remove in the character value string with substr_to_replace.
Syntax
Example
Output:$c$c$c$c
REVERSE
Reverse the input string.
Syntax
Example
Output:dcba
RIGHT
Return the number of trailing characters in the string equal to the value integer.
Syntax
Example
Output:arehouse
Example
Output:ent data warehouse
RPAD
Pad the input text to the specified length with the pad string on the right side. If text is longer than length, it is truncated to length characters. If the argument pad is not provided, the space character is used.
Syntax
Example
Output:ocient data warehouse
Example
Output:ocient data warehouseababababa
RSUBSTRING
Returns the substring from the right side of a string, based on a specified length.
Syntax
Example
Output:data warehouse
RTRIM
Removes trailing blanks from the string value string.
Alternatively, you can specify a second string value trim_character. If you specify the trim_character value, the RTRIM function removes all trailing instances of the trim_character value from the string.
Syntax
Example
Output:ocient
Example
Output:ocient
SHA1
Uses the SHA-1 cryptographic hash function to convert a string into a 40-character string representing the hexadecimal value of a 160-bit checksum.
Syntax
Example
Output:0c2a9a042b9f047f875c3414e7a4f4c53efbe082
SPACE
Returns a string of repeated spaces equal to the number value, repeat. You can join this to another string by using the CONCAT function.
Syntax
Example
Output: end
SPLIT_PART
Split the value string based on the delimiter value. The function returns a substring from the split operation based on the index value (starting from 1).
Syntax
Example
Output:id
Example
Output:name
Example
Output:address
SPLIT_TO_ARRAY
Splits a string into an array of substrings.
Syntax
Example
This example specifies | as the delimiter to split the input string.
Output:['AB','CD','EF']
STARTSWITH
Returns true if string starts with substring and false otherwise.
Syntax
Example
Output:true
Example
Output:false
STRPOS
Equivalent to using LOCATE as LOCATE(substring, string). Note the reversed argument order.
Syntax
Example
Output:17
SUBSTR
Alias for SUBSTRING.
SUBSTRING
Alias for SUBSTR and MID.
Returns the substring of a character or binary value that starts with the position specified by the second argument and that ends with the position specified by one less than the sum of the second and third arguments. When the sum of the second and third arguments is less than two, the function returns the empty string.
Syntax
Example
Output:data warehouse
Example
Output:data
TO_CHAR
Converts a numeric, date, or timestamp value into a CHAR date type.
Example
Output:2020-06-10
Example
Output:13:25:14
TRANSLATE
Replaces specified characters in a provided string with a separate set of characters.
Characters specified in the char_to_remove set are replaced with characters in the char_to_replace set based on the corresponding index position.
Syntax
Example
Output:gbhdif
TRIM
Alias for BTRIM.
Trim leading and trailing space characters from the string.
Alternatively, you can specify a second string value trim_char. If a trim_char value is provided, the TRIM function removes all leading and trailing instances of the trim_char value from the string.
Syntax
Example
Output:trimmed string
Example
Output:trimmed string
UCASE
Alias for UPPER.
UPPER
Alias for UCASE.
Convert string to upper case.
Syntax
Example
Output:OCIENT
Concatenate Operator(||)
The || operator concatenates two strings. If you specify a NULL string, the result is NULL.
||Syntax
Examples
Concatenate Two Strings
Concatenate two strings.
Output: 'hello world'
Concatenate a NULL String
Concatenate two strings, one of which is NULL.
Output: NULL

